我已经尝试了很多可能对这个问题的解决问题后,我的问题并没有被解决:didRefreshRegistrationToken如果用户不允许不会被调用的通知迅速
我想FCM Token
。在AppDelegate.swift
我已经导入
import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
之后,我已经与UNUserNotificationCenterDelegate, MessagingDelegate
扩展它,然后在didFinishLaunchingWithOptions
我说:
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
// For iOS 10 data message (sent via FCM
Messaging.messaging().delegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
FirebaseApp.configure()
此后,我已经添加了这四个函数:
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken as Data
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
print("Here")
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
现在的问题是,当我运行应用程序,它显示警报,要求发送通知的权限。允许或禁止它不是我所关心的,我已经实施了MessagingDelegate
方法didRefreshRegistrationToken
所以它应该被调用,但它没有调用该方法。所以我错过了什么?