Auf iOS10, wenn eine App geöffnet ist, erhalte ich Push-Benachrichtigungen, aber wenn ich die Home-Taste drücke und die App im Hintergrundmodus ist, erhält sie nichts.Warum erhält ein Gerät keine Push-Benachrichtigung im Hintergrund?
Mein Code ist:
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()
}
So kann ich nicht finden, wo ist das Problem? Irgendeine Idee? Oder gibt es etwas Neues in iOS10?
drehte ich mich schon auf diese Funktionen:
func Anwendung (Anwendung: UIApplication, didReceiveRemoteNotification userinfo: [NSObject: ANYOBJECT], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { completionHandler (.NewData) } brauchen – dragoneye