How can I get notification in iOS 10? In previous version, I can receive notification in func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
.
In iOS 10, Apple introduces UNNotificationSettings
. I can get FCM with func applicationReceivedRemoteMessage(remoteMessage: FIRMessagingRemoteMessage)
.
However, I cannot get notification showing up on my phone in the background.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { FIRApp.configure() if #available(iOS 10.0, *) { let authOptions : UNAuthorizationOptions = [.Alert, .Badge, .Sound] UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions( authOptions, completionHandler: {_,_ 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) application.registerForRemoteNotifications() } return true } @available(iOS 10, *) extension AppDelegate: UNUserNotificationCenterDelegate, FIRMessagingDelegate { // Receive displayed notifications for iOS 10 devices. func userNotificationCenter(center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { let userInfo = notification.request.content.userInfo // Print message ID. print("Message ID: \(userInfo["gcm.message_id"]!)") // Print full message. print("%@", userInfo) } // Receive data message on iOS 10 devices. func applicationReceivedRemoteMessage(remoteMessage: FIRMessagingRemoteMessage) { print("%@", remoteMessage.appData) } }