Firebase Auth使用电话号码返回内部错误

Lau*_*ent 13 apple-push-notifications ios firebase firebase-authentication

我设置了我的应用程序,以便能够使用firebase发送Apple Notifications,并且我使用控制台验证了它的工作原理.现在我想做一个建立在APN之上的电话认证.

所以我写了这个:

PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { verificationID, error in
  if error != nil {
    print("Verification code not sent \(error!)")
  } else {
    print ("Successful.")
  }
Run Code Online (Sandbox Code Playgroud)

我得到:

Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSUnderlyingError=0x170046db0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
    code = 500;
    message = "<null>";
}}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.}
Run Code Online (Sandbox Code Playgroud)

任何的想法?我应该提交针对firebase的错误吗?

我正在使用iOS SDK 4.0.0(我能找到最新的zip.)

更新:

加入我禁用方法混写FirebaseAppDelegateProxyEnabledinfo.plist并将其设置为NO

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Pass device token to auth.
    Auth.auth().setAPNSToken(deviceToken, type: .prod)
}
Run Code Online (Sandbox Code Playgroud)

Arp*_*ain 8

使用最新的Firebase iOS SDK测试,即4.0.0Xcode 8.3

首先,FirebaseAppDelegateProxyEnabled从info.plist中删除此密钥.这不是必需的.

现在在AppDelegate.swift中添加以下函数

import Firebase
import UserNotifications

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate , UNUserNotificationCenterDelegate{
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
                options: authOptions,
                completionHandler: {_, _ in })
        } else {
            let settings: UIUserNotificationSettings =
                UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }

        application.registerForRemoteNotifications()
        FirebaseApp.configure()
        return true
    }
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Pass device token to auth.
    let firebaseAuth = Auth.auth()

    //At development time we use .sandbox
    firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)

    //At time of production it will be set to .prod
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    let firebaseAuth = Auth.auth()

    if (firebaseAuth.canHandleNotification(userInfo)){
        print(userInfo)
        return
    }
}*
Run Code Online (Sandbox Code Playgroud)

将验证码发送到用户的手机:

在要集成电话身份验证的类中写入:

注意:我已添加+91为印度的国家/地区代码.您可以根据您所在的地区添加国家/地区代码

 PhoneAuthProvider.provider().verifyPhoneNumber("+919876543210") { (verificationID, error) in
       if ((error) != nil) {
             // Verification code not sent.
             print(error)
       } else {
              // Successful. User gets verification code 
              // Save verificationID in UserDefaults
             UserDefaults.standard.set(verificationID, forKey: "firebase_verification")
             UserDefaults.standard.synchronize()
             //And show the Screen to enter the Code.
       }               
Run Code Online (Sandbox Code Playgroud)

使用验证码登录用户:

 let verificationID = UserDefaults.standard.value(forKey: "firebase_verification")
 let credential = PhoneAuthProvider.provider().credential(withVerificationID: verificationID! as! String, verificationCode: self.txtEmailID.text!)

   Auth.auth().signIn(with: credential, completion: {(_ user: User, _ error: Error?) -> Void in
         if error != nil {
            // Error
          }else {
             print("Phone number: \(user.phoneNumber)")
              var userInfo: Any? = user.providerData[0]
                    print(userInfo)
                }
         } as! AuthResultCallback)
Run Code Online (Sandbox Code Playgroud)


fed*_*608 5

就我而言,这是错误的 apns 令牌类型:

Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
Run Code Online (Sandbox Code Playgroud)

本来应该:

Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)
Run Code Online (Sandbox Code Playgroud)