【发布时间】:2018-08-03 10:58:16
【问题描述】:
我正在尝试开发一个信使应用程序,当应用程序处于前台或后台时,客户端只需要发送静默通知。
它在 IOS 10.2.1 Verizon iPhone 中完美运行。
更新到 11.4.1 后,通知只能在前台工作,而不能在后台工作。
有效载荷:
{
"to" : "/topics/channel_18",
"data" : {
"action" : "NOTIFY",
"message" : "{"text":"test" }"
},
"content_available" : true
}
代码:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Messaging.messaging().appDidReceiveMessage(userInfo)
let action = userInfo["action"] as! String
// Configure the notification's payload.
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Hello!", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: "testing", arguments: nil)
content.sound = .none
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: "FiveSecond", content: content, trigger: trigger) // Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request) { (error : Error?) in
if let theError = error {
}
}
completionHandler(UIBackgroundFetchResult.newData)
}
我已经浏览了链接Silent pushes not delivered to the app on iOS 11,但找不到解决方案。
【问题讨论】:
-
似乎在 iOS 11.1 中解决了静默通知问题,并且您正在使用它应该工作的 11.4。确保您使用
application:didReceiveRemoteNotification:fetchCompletionHandler作为接收器方法。 -
请检查我更新的问题。上述方法是否有任何改变?
-
我在 iOS 13 上的设置几乎相同,并且实际传递到我的应用程序的静默推送量受到限制,而不是在某一时刻受到限制。当我取消订阅并重新订阅时,我可以成功获得一个。还有一次,我确实在不到 20 秒的时间内收到了大约 4 个。
标签: swift firebase apple-push-notifications firebase-cloud-messaging ios11.4