这是我的代码:
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")
}
}
}
这是控制台打印出的内容:
错误域= FIRAuthErrorDomain代码= 17048"无效令牌。" UserInfo = {NSLocalizedDescription =无效令牌。, ERROR_NAME = INVALID_APP_CREDENTIAL}
我做错了什么?感谢
答案 0 :(得分:9)
我也遇到了这个问题。检查以下内容:
aps-environment
值auth.setAPNStoken
时调整APNS令牌类型(.unknown
进行自动检测)在Firebase应用设置中我没有任何帮助我上传了APNS身份验证密钥(p8)而不是证书 - 我之前只使用这些证书进行推送通知并且一切正常但是对于电话号码通知出了问题。
答案 1 :(得分:2)
首先重新生成APNS密钥并上传到Firebase中以进行云消息传递
1)导入Firebase和FirebaseAuth
import Firebase
import FirebaseAuth
2)在didFinishLaunchingWithOptions中配置firebase。
FirebaseApp.configure()
3)在AppDelegate中编写这两个函数。
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.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
}
}
非常重要的说明:uthAPNSTokenType
已为[沙盒/生产]正确设置,或为常见的.unknown
设置
在我的情况下,错误的是apns令牌类型:
Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
应该是:
Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)
答案 2 :(得分:2)
最有可能需要上传.p8密钥文件
(我有一个企业帐户,但对于开发人员来说却是一样的)
在Apple开发者帐户中:
答案 3 :(得分:1)
关于SO的问题曾经是相同的。因此想告诉您在运行代码之前设置所有先决条件步骤。
先决步骤:
在开发者帐户上注册捆绑包ID并启用以下通知: 捆绑包ID。
在Firebase控制台设置页面上注册相同的捆绑包ID并创建 应用程序,下载Google-Info.plist文件,确保名称相同。
在Firebase控制台上为沙箱以及 开发。
按照下面的链接进行代码实现。
答案 4 :(得分:0)
答案 5 :(得分:0)
就我而言,问题是iOS应用中Firebase项目设置中的 bundle ID不正确(项目设置->常规->您的应用)。
我希望这能帮助任何忽略相同细节的人。
答案 6 :(得分:0)