swift 在iOS应用程序中启用APN后,Firebase电话身份验证“无效令牌”错误

nkhmeac6  于 5个月前  发布在  Swift
关注(0)|答案(1)|浏览(41)

我正在开发一个iOS应用程序,使用Firebase手机身份验证进行登录和注册。在我集成Apple推送通知服务(APN)从后端直接推送通知(而不是通过Firebase)之前,此设置一直正常运行。发布此集成并在Xcode中启用APN后,我遇到了一个'无效令牌'错误,特别是在尝试Firebase身份验证时。
这是我在登录时遇到的错误:

let verificationID = UserDefaults.standard.string(forKey: "authVerificationID")
        
        PhoneAuthProvider.provider()
            .verifyPhoneNumber(self.phone_no, uiDelegate: nil) { verificationID, error in
                if let error = error {
                    print("-----------PHONE AUTH:",error.localizedDescription) //Getting invalid token here
                    return
                }
                UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
            }

字符串
这是我在AppDelegate中为推送通知添加的代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        
        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { success, _ in
            guard success else {
                return
            }
            print("Success in APNS registry")
        }
        
        application.registerForRemoteNotifications()
        
        
        UIApplication.shared.isIdleTimerDisabled = true
        
        
        return true;
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let tokenParts = deviceToken.map { data -> String in
            return String(format: "%02.2hhx", data)
        }
        let token = tokenParts.joined()
        UserInfo.apnToken = token
        print("Messaging Delegate Token: \(token)")
        print("Messaging Delegate Token UserInfo: \(UserInfo.apnToken)")
        //NotificationUtils.updateDeviceToken();
    }


我希望Firebase身份验证能像以前一样继续工作,即使在APN集成之后。然而,APN的引入似乎与Firebase auth token冲突。我没有在控制台后APN设置中对Firebase设置进行任何更改。

afdcj2ne

afdcj2ne1#

听起来像是为了获得推送令牌而进行的搅拌,然后当您自己显式地获得它时,它现在不再可以访问它。
我不知道这个Firebase API,但想必一定有一个API让你在自己获得推送令牌后将其传递给它。
看看他们的医生关于搅拌和如何关闭它等
https://firebase.google.com/docs/cloud-messaging/ios/client

相关问题