【问题标题】:Firebase Authenticate using a Phone Number: use of unresolved identifier AuthAPNSTokenTypeProd and UIBackgroundFetchResultNoData errorFirebase 使用电话号码进行身份验证:使用未解析的标识符 AuthAPNSTokenTypeProd 和 UIBackgroundFetchResultNoData 错误
【发布时间】:2017-06-04 10:06:06
【问题描述】:

我正在使用电话号码在 iOS 上将 Authenticate 与 Firebase 集成,并且我在此link. 中的文档中提到的过程的初始实施中遇到了错误

我按照他们提到的程序安装了 pod 并导入了 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'”。

我不确定我在实施中缺少的程序。执行过程我已经走很多遍了,没发现错误。

【问题讨论】:

  • 你是在模拟器还是真机上试过这个?
  • 我在设备上工作,但这并不重要,因为该项目不会作为编译时错误自行运行。无论如何,如果我从代码中排除这些方法,让方法调配处于活动状态,并继续实施,Firebase Auth 正在工作。但是如果想禁用方法调配,那么我需要编写这些方法,但这是行不通的。

标签: ios firebase swift3 firebase-authentication appdelegate


【解决方案1】:

请尝试以下代码

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.
}

【讨论】:

    【解决方案2】:

    原来AuthAPNSTokenTypeProd不是数据类型或枚举大小写。 iOS 的电话验证实施步骤中似乎存在错误。

    您正在寻找与 Obj-C 枚举关联的 AuthAPNSTokenType:FIRAuthAPNSTokenType。

    您可以在 FirebaseAuth 框架/依赖项中找到源代码。

    所以解决你的一个问题应该是改变这一行:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 2018-12-17
      相关资源
      最近更新 更多