首页 > 解决方案 > Swift:firebase didRegisterForRemoteNotificationsWithDeviceToken 在某些设备上不起作用

问题描述

我的代码:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    print("Message: \(deviceToken)")
}

打开iphone 8 plusiphone 6打印设备令牌但iphone 6s不起作用

iphone 8 plusiphone 6s版本是11.4

结果iphone 8 plusiphone 6收到通知但未iphone 6s收到

我的代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()

        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().delegate = self

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

        } else {
            let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }

        application.registerForRemoteNotifications()

        if((Messaging.messaging().fcmToken) != nil){
            AppDelegate.USERTOKEN = (Messaging.messaging().fcmToken)!
        }

        print("Message APP: \(AppDelegate.USERTOKEN)")

        return true
    }

注意:print("Message APP: \(AppDelegate.USERTOKEN)")适用于所有设备并打印令牌。

标签: iosswiftfirebaseremote-notifications

解决方案


推荐阅读