Firebase使用电话号码进行身份验证:使用未解析的标识符AuthAPNSTokenTypeProd和UIBackgroundFetchResultNoData错误

时间:2017-06-04 10:06:07

标签: ios firebase swift3 firebase-authentication appdelegate

我正在使用电话号码在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'”。

我不确定我在实施中缺少的程序。我已多次执行实施程序,我找不到错误。

2 个答案:

答案 0 :(得分:6)

请尝试以下代码

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

答案 1 :(得分:0)

事实证明AuthAPNSTokenTypeProd不是数据类型或枚举情况。似乎iOS的电话身份验证实施步骤中存在错误。

您正在寻找与Obj-C枚举相关联的AuthAPNSTokenTypeFIRAuthAPNSTokenType

您可以在 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