我正在尝试开发一个信使应用程序,当应用程序处于前台或后台时,客户端只需要发送静默通知。
它在 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的链接,但我找不到解决方案。