For iOS 12 or higher display notification (sent via APNS)

120 Views Asked by At

Register for remote notifications For iOS 12 or higher display notification (sent via APNS) I just need to add the below code, right?

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })

        application.registerForRemoteNotifications()

No need if-else like the example for iOS 10: https://github.com/firebase/quickstart-ios/blob/365e43642f2cc570df004cb16e098a76cde1e5b1/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55

1

There are 1 best solutions below

0
On

That’s right. I've tried this code and it works well.

For devices running iOS 10 and above, you must assign the UNUserNotificationCenter's delegate property and FIRMessaging's delegate property. For example, in an iOS app, assign it in the applicationWillFinishLaunchingWithOptions: or applicationDidFinishLaunchingWithOptions: method of the app delegate.