我试图实现我的应用程序火力点云的消息。didReceiveRemoteNotification前景火力云消息不叫于iOS
我使用下面的代码
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
,一切工作正常时,应用程序是在回地面注册的通知,但是当应用程序在前台,didReceiveRemoteNotification根本没有被调用。
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Print message ID.
print("please help")
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
completionHandler(.newData)
}
任何人都知道这个可能的错误?谢谢!
编辑:我不需要看到的通知显示,当应用程序在前台,我只是想从通知
这个完成处理程序根本不能调用吗? –
是否声明UNUserNotificationCenterDelegate? – Mohit