输入'NSNotification.Name?' 没有成员'firInstanceIDTokenRefresh'

Ami*_*mit 1 ios firebase swift firebase-cloud-messaging

我在使用Swift的iOS应用中使用Firebase通知,最近我将Firebase Messaging从1.2.3更新为2,我的代码开始向右和向右突破.我解决了大部分问题,但我坚持这个问题.

这是我的部分AppDelegate应用程序功能导致我的问题:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UIApplication.shared.statusBarStyle = .lightContent
    ...

    FirebaseApp.configure()

    // [START add_token_refresh_observer]
    // Add observer for InstanceID token refresh callback.
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(self.tokenRefreshNotification),
                                           name: .firInstanceIDTokenRefresh,
                                           object: nil)
    // [END add_token_refresh_observer]

    return true
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行我的应用程序时,出现以下错误:

输入'NSNotification.Name?' 没有成员'firInstanceIDTokenRefresh'

已将firInstanceIDTokenRefresh重命名为其他内容吗?

pau*_*lvs 14

看来此通知已被委托方法取代.

火力地堡云端通讯文档提到如何监测令牌生成:

监控令牌生成

要在更新令牌时收到通知,请提供符合FIRMessagingDelegate协议的委托.以下示例注册委托并添加适当的委托方法:

func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
    print("Firebase registration token: \(fcmToken)")
}
Run Code Online (Sandbox Code Playgroud)

编辑

文档还提到仍然可以使用通知,现在调用它Notification.Name.MessagingRegistrationTokenRefreshed.