首页 > 解决方案 > Firebase 电话身份验证失败

问题描述

我想使用电话身份验证进行 Firebase 登录。由于我正在开发并且我无权访问设备和 Apple 开发人员帐户,所以我去使用实现此功能

reCAPTCHA 验证

但我收到以下错误

{"error":{"code":403,"message":"来自此 ios 客户端应用程序的请求被阻止。","errors":[{"message":"来自此 ios 客户端应用程序的请求被阻止。", “域”:“全局”,“原因”:“禁止”}],“状态”:“PERMISSION_DENIED”}}

正如文档中所示,我已经实现了这一点。

下面是 AppDelegate.swift 中的代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    return true
}

// For iOS 9+
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
    if Auth.auth().canHandle(url) {
        return true
    }
    return false
    // URL not auth related, developer should handle it.
}

下面是 ViewController.swift 中的代码:

@IBAction func didTapSignUp(_ sender: Any) {
    PhoneAuthProvider.provider().verifyPhoneNumber("+919637892151", uiDelegate: nil) { (verificationId, error) in
        if let error = error {
            // It always comes here
            print(error.localizedDescription)
        }
        if let verificationId = verificationId {
            print(verificationId)
            UserDefaults.standard.set(verificationId, forKey: "authVerificationID")
        }
    }
}

标签: iosswiftfirebasefirebase-authentication

解决方案


我遵循了这个答案并且它有效。

“将 Google 控制台中的 API 密钥密钥限制设置为 NONE”

我很困惑,因为如果只有 NONE 有效,它的目的是什么?


推荐阅读