ios10, Swift 3 and Firebase Push Notifications (FCM)

后端 未结 3 1516
温柔的废话
温柔的废话 2020-12-17 03:20

I am struggling to display my push notifications that I am sending to my device from the FCM notification console. I can see the device is receiving the notification becaus

3条回答
  •  情话喂你
    2020-12-17 04:06

    You need to move

     application.registerForRemoteNotifications()
    

    it should not be inside the else.

    // [START register_for_notifications]
        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()
    

    See following commit in Firebase

提交回复
热议问题