“无效令牌"尝试使用 firebase 验证电话号码时 [英] "Invalid Token" when trying to authenticate phone number using firebase

查看:18
本文介绍了“无效令牌"尝试使用 firebase 验证电话号码时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

这是控制台打印出来的:

This is what the console prints out:

错误域=FIRAuthErrorDomain 代码=17048 无效令牌."UserInfo={NSLocalizedDescription=无效的令牌.,error_name=INVALID_APP_CREDENTIAL}

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token." UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL}

我做错了什么?谢谢

推荐答案

我也遇到了这个问题.检查了以下内容:

I was also experiencing this problem. Checked the following:

  • 正确的包 ID
  • 更正 Google-Info.plist
  • 正确的aps-environment
  • 调用 auth.setAPNStoken 时正确的 APNS 令牌类型(.unknown 用于自动检测)
  • Correct bundle Id
  • Correct Google-Info.plist
  • Correct aps-environment value
  • Correct APNS token type when calling auth.setAPNStoken (.unknown for auto detect)

直到在 Firebase 应用设置中我上传了 APNS 身份验证密钥 (p8) 而不是证书之前没有任何帮助 - 我之前仅将这些证书用于推送通知,并且一切正常,但对于电话号码通知出错了.

Nothing helped until in Firebase app settings I uploaded the APNS authentication key (p8) instead of certificates - I used those certificates before for push notifications only and everything was working fine but for phone number notifications something went wrong.

这篇关于“无效令牌"尝试使用 firebase 验证电话号码时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆