标签: unnotificationrequest

xcode 8推送通知功能和权利文件设置

使用时xcode 8做推送通知设置,不像xcode 7,xcode 8需要推送通知功能切换开发商转(位于TARGETS -> AppName -> Capabilities如下图), 推送通知功能

然后它将生成AppName.entitlements文件,如下所示

//AppName.entitlements
<key>aps-environment</key>
<string>development</string>
Run Code Online (Sandbox Code Playgroud)

但对于生产版App,如果我们将字符串更改为

//AppName.entitlements
<key>aps-environment</key>
<string>production</string>
Run Code Online (Sandbox Code Playgroud)

然后功能显示警告

能力警告

似乎无论在aps-environment中指定了哪个字符串值,我们仍然可以获得推送设备令牌 application:didRegisterForRemoteNotificationsWithDeviceToken:

那么推送通知权利的正确设置是什么?谢谢

push-notification ios10 xcode8 unnotificationrequest xcode8-beta6

64
推荐指数
1
解决办法
3万
查看次数

UNUserNotificationCenter removeAllDeliveredNotifications在ios 11.2中不起作用

我有一个包含多个本地通知的应用.当我尝试清除所有已发送的通知时,我称之为此removeAllDeliveredNotifications方法.它工作正常,直到ios 11.1.在ios 11.2以上,预期这是行不通的.通知仍保留在通知中心.有人可以帮我解决这个问题.

提前致谢.

ios uilocalnotification unnotificationrequest

11
推荐指数
1
解决办法
1294
查看次数

如何在iOS 10 UserNotifications上设置NSCalendarUnitMinute repeatInterval?

在UILocalNotification我们使用NSCalendarUnitMinute像重复.....但我在iOS 10 UserNotification doc中找不到...我怎样才能NSCalendarUnitMinute在iOS 10中使用类似的重复UserNotification

这是代码,它将在晚上8:30安排本地通知,并在每一分钟后重复.

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.textField.text;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = NSCalendarUnitMinute;
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Run Code Online (Sandbox Code Playgroud)

objective-c ios swift ios10 unnotificationrequest

9
推荐指数
1
解决办法
4244
查看次数

访问UNNotificationRequest对象的计划日期

我试图找到UNNotificationRequest对象的预定开火日期.

我正在提取这样的待处理通知请求:

UNUserNotificationCenter.current().getPendingNotificationRequests { (notifications) in

        let pendingNotifications : [UNNotificationRequest] = notifications
    }
Run Code Online (Sandbox Code Playgroud)

然后我尝试访问每个UNNotificationRequest对象的触发日期.

我可以按如下方式访问UNNotificationTrigger,但无法找到访问通知的计划发布日期的方法.

let notification = pendingNotifications[indexOfNotification]
let trigger : [UNNotificationTrigger] = notification.trigger
Run Code Online (Sandbox Code Playgroud)

我已经能够访问一些通知的日期,如下所示:

let date = trigger.value(forKey: "date") as! Date
Run Code Online (Sandbox Code Playgroud)

这适用于使用UNUserNotificationCenter安排的通知,但在尝试访问iOS 10之前安排的通知日期时出现以下错误.

由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[valueForUndefinedKey:]:此类不是关键日期的密钥值编码兼容.

是否有一种方法可以同时支持新旧通知.

谢谢.

ios ios10 unnotificationrequest unusernotificationcenter

9
推荐指数
1
解决办法
1821
查看次数

iOS 10中的本地通知限制(UNNotificationRequest)

我知道UILocalNotification的本地通知限制为64 .它是用Apple Dev Docs编写的.但UILocalNotification在iOS 10中已弃用.相反,Apple建议使用UNNotificationRequest.但Apple Dev Docs没有说明限制通知的数量.我找到了这个答案,但它没有Apple Dev Docs的链接或类似的东西(这只是一个意见).有没有人确切知道本地通知的限制?也许有人知道Dev Docs的链接,还是苹果对此有官方回应?

ios unnotificationrequest

8
推荐指数
2
解决办法
1587
查看次数

如何让 UNNotificationRequest 立即弹出?

我正在使用UNNotificationRequest并且我希望当我单击按钮时立即弹出通知。但在这种情况下,它出现在我退出应用程序时。这是我的代码

@IBAction func shortNotifBtn(_ sender: Any) {
    let center = UNUserNotificationCenter.current()
    let content = UNMutableNotificationContent()
    content.title = "Late wake up call"
    content.body = "The early bird catches the worm, but the second mouse gets the cheese."
    content.categoryIdentifier = "alarm"
    content.userInfo = ["customData": "fizzbuzz"]
    content.sound = UNNotificationSound.default()
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
    let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
    center.add(request)
}
Run Code Online (Sandbox Code Playgroud)

notifications ios swift ios10 unnotificationrequest

8
推荐指数
2
解决办法
3532
查看次数

UNUserNotificationCenter单元测试

我尝试测试一种简单的方法,该方法应该为iOS 10创建并传递通知。

func displayPlaceNotificationContent() {
    let unMutableNotificationContent = generateNotification()
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
    let request = UNNotificationRequest(identifier: getNotificationIdentifier(), content: unMutableNotificationContent, trigger: trigger)
    let notificationCenter = UNUserNotificationCenter.current()
    notificationCenter.add(request, withCompletionHandler: nil)
}  
Run Code Online (Sandbox Code Playgroud)

这是此方法的单元测试:

func testDisplayNotification() {
    notificationManager?.displayPlaceNotificationContent())
    XCTAssertTrue((notificationManager.isNotificationDisplayed())
}
Run Code Online (Sandbox Code Playgroud)

当我尝试执行单元测试时,我有一个异常,即堆栈跟踪:

2017-09-12 13:52:25.931564+0200 xctest[17170:1252988] *** Assertion failure in -[UNUserNotificationCenter initWithBundleProxy:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UserNotifications_Sim/UserNotifications-156/UNUserNotificationCenter.m:50
2017-09-12 13:52:25.933629+0200 xctest[17170:1252988] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: bundleProxy != nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010b0a9aeb __exceptionPreprocess …
Run Code Online (Sandbox Code Playgroud)

xcode unit-testing ios swift3 unnotificationrequest

6
推荐指数
0
解决办法
653
查看次数

在 iOS 15 之前,我只能发送声音本地通知,现在我必须显示横幅

这在 iOS 15 之前运行良好

let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
        content.sound = UNNotificationSound.init(named:UNNotificationSoundName(rawValue: sound))
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
center.add(request)
Run Code Online (Sandbox Code Playgroud)

用户收到通知声音,iOS 15 之后我必须添加

content.body = "Hello iOS 15"
Run Code Online (Sandbox Code Playgroud)

无论如何,只能在 iOS 15 上发送带有声音的本地通知?

notifications ios unnotificationrequest ios15

6
推荐指数
1
解决办法
730
查看次数

应用在后台时的Firebase监听器

我的childAdded应用中的通知表有一个Firebase 事件监听器,我想在应用程序在后台时触发推送通知.

这是听众:

@objc func observeNotificationsChildAddedBackground() {
    self.notificationsBackgroundHandler = FIREBASE_REF!.child("notifications/\(Defaults.userUID!)")
    self.notificationsBackgroundHandler!.queryOrdered(byChild: "date").queryLimited(toLast: 99).observe(.childAdded, with: { snapshot in
        let newNotificationJSON = snapshot.value as? [String : Any]
        if let newNotificationJSON = newNotificationJSON {
            let status = newNotificationJSON["status"]
            if let status = status as? Int {
                if status == 1 {
                    self.sendPushNotification()
                }
            }
        }
    })
}

func sendPushNotification() {
    let content = UNMutableNotificationContent()
    content.title = "Here is a new notification"
    content.subtitle = "new notification push"
    content.body = "Someone did something …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift firebase-cloud-messaging unnotificationrequest

5
推荐指数
1
解决办法
7101
查看次数

将Date转换为DateComponents函数以在Swift 3中安排本地通知

我正在尝试设置一个接收整数的函数,并在将来的n天内安排本地通知.我收到一个错误,我无法将类型Date转换为DateComponents.我无法弄清楚如何转换它.我在这里这里找到了一些其他类似的问题,但我无法使这些答案适应Swift 3的工作.

如何将Date转换为DateComponents?有没有更好的方法来安排通知?

在此先感谢您的帮助 :)

带有错误的行,"无法转换类型'日期的值?' 预期的参数类型'DateComponents'":

let trigger = UNCalendarNotificationTrigger(dateMatching: fireDateOfNotification, repeats: false)
Run Code Online (Sandbox Code Playgroud)

功能齐全:

func scheduleNotification(day:Int) {    
    let date = Date()
    let calendar = Calendar.current
    var components = calendar.dateComponents([.day, .month, .year], from: date as Date)
    let tempDate = calendar.date(from: components)
    var comps = DateComponents()

    //set future day variable
    comps.day = day

    //set date to fire alert
    let fireDateOfNotification = calendar.date(byAdding: comps as DateComponents, to: tempDate!)

    let trigger = UNCalendarNotificationTrigger(dateMatching: fireDateOfNotification, repeats: false) //THIS LINE CAUSES …
Run Code Online (Sandbox Code Playgroud)

ios swift unnotificationrequest

5
推荐指数
1
解决办法
5061
查看次数