Firebase 使用 Phone 数字进行身份验证:使用未解析的标识符 AuthAPNSTokenTypeProd 和 UIBackgroundFetchResultNoData 错误

Firebase Authenticate using a Phone Number: use of unresolved identifier AuthAPNSTokenTypeProd and UIBackgroundFetchResultNoData error

我正在 iOS 上使用 Phone 号码将 Authenticate 与 Firebase 集成,但我在 link.[link.[他们的文档中提到的程序的初始实施中遇到了错误=14=]

我按照他们提到的程序安装了 pods 并导入了 firebase SDK。 错误来自以下两种方法:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  // Pass device token to auth
  Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenTypeProd)

  // Further handling of the device token if needed by the app
  // ...
}

func application(_ application: UIApplication,
didReceiveRemoteNotification notification: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if Auth.auth().canHandleNotification(notification) {
    completionHandler(UIBackgroundFetchResultNoData)
    return
  }
  // This notification is not auth related, developer should handle it.
}

它说“使用未解析的标识符 'AuthAPNSTokenTypeProd'”和“使用未解析的标识符 'UIBackgroundFetchResultNoData'” .

我不确定我在实施中缺少的程序。执行过程我已经看了很多遍了,找不到错误。

请尝试以下代码

Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)

还有这个

func application(_ application: UIApplication,
                 didReceiveRemoteNotification notification: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    if Auth.auth().canHandleNotification(notification) {
        completionHandler(UIBackgroundFetchResult.noData)
        return
    }
    // This notification is not auth related, developer should handle it.
}

事实证明AuthAPNSTokenTypeProd不是数据类型或枚举大小写。 iOS.

的 Phone 身份验证实施步骤似乎有误

您正在查找与 Obj-C 枚举关联的 AuthAPNSTokenTypeFIRAuthAPNSTokenType.

您可以在 FirebaseAuth framework/dependency.

中找到源代码

所以您的问题之一的解决方案应该是更改此行:

Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenTypeProd)

对此:

Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)

文档:Authenticate with Firebase on iOS using a Phone Number

API参考:FirebaseAuth Framework Reference - FIRAuthAPNSTokenType