我試圖實現我的應用程序火力點雲的消息。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