我的代码:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("Message: \(deviceToken)")
}
在iphone 8 plus
和iphone 6
打印设备令牌上,但在iphone 6s
上无效
iphone 8 plus
和iphone 6s
的版本是11.4
结果iphone 8 plus
和iphone 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)")
适用于所有设备并打印令牌。