Push Notification not showing in iOS 10

后端 未结 1 1239
攒了一身酷
攒了一身酷 2021-01-24 11:04

How can I get notification in iOS 10? In previous version, I can receive notification in func application(application: UIApplication, didReceiveRemoteNotification user

相关标签:
1条回答
  • 2021-01-24 11:57

    you have to move this method

    application.registerForRemoteNotifications()

    to above return statement.

    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()
    
       NotificationCenter.default.addObserver(self,
                                               selector: #selector(self.tokenRefreshNotification),
                                               name: .firInstanceIDTokenRefresh,
                                               object: nil)
    
        return true
     }
    
    0 讨论(0)
提交回复
热议问题