简体   繁体   中英

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

I am integrating Authenticate with Firebase on iOS using a Phone Number and I am having errors in the initial implementation of the procedure as mentioned in their document in this link.

I followed the procedure mentioned their, installed the pods and imported the firebase SDK. The error comes in the following two methods:

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

and

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

It says " use of unresolved identifier 'AuthAPNSTokenTypeProd' " and " use of unresolved identifier 'UIBackgroundFetchResultNoData' ".

I am not sure about the procedure I am missing in the implementation. I have gone through the implementation procedure many times, I can't find the mistake.

Please try following code

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

and this

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

It turns out AuthAPNSTokenTypeProd is not a data type or enum case. It seems like there's a mistake in the Phone Authentication implementation steps for iOS.

You're looking for AuthAPNSTokenType which is associated with the Obj-C enum: FIRAuthAPNSTokenType .

You can find the source inside the FirebaseAuth framework/dependency.

So the solution to one of your problems should be to change this line:

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

to this:

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

Docs: Authenticate with Firebase on iOS using a Phone Number

API Reference: FirebaseAuth Framework Reference - FIRAuthAPNSTokenType

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM