在iOS10上打開應用時,我收到推送通知,但是當我按Home按鈕並且應用處於後臺模式時 - 它不會收到任何內容。爲什麼設備在後臺沒有收到推送通知?
我的代碼是:
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, FIRMessagingDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if #available(iOS 10.0, *) {
let authOptions: UNAuthorizationOptions = [.Alert, .Badge, .Sound]
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Sound, .Alert, .Badge], completionHandler: { (granted: Bool, error: NSError?) in
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.currentNotificationCenter().delegate = self
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self
})
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
application.registerForRemoteNotifications()
}
}
@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
}
@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler:() -> Void) {
//Handle the notification
print("User Info => ",response.notification.request.content.userInfo)
completionHandler()
}
所以我無法找到問題出在哪裏?任何想法?或者iOS10中有新的東西?
我已經開啓這些功能:
FUNC申請(申請:UIApplication的,didReceiveRemoteNotification USERINFO:[NSObject的:AnyObject],fetchCompletionHandler completionHandler:(UIBackgroundFetchResult) - >空隙){ completionHandler(.NewData) } 需要背景取 – dragoneye