You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase手机号认证报错:UIApplicationDelegate未处理远程通知

Firebase手机号认证报错[I-AUT000015]解决指南

核心问题说明

这个报错的本质是:Firebase手机号认证依赖APNs推送通道下发验证码,即使你的App普通推送正常,认证流程的推送处理有特殊逻辑要求,必须让Firebase Auth能接收到并处理对应的推送消息。


具体排查与解决步骤

1. 检查Firebase AppDelegate Swizzling配置

Firebase默认会自动Swizzle AppDelegate的推送回调方法,帮你处理认证推送。如果手动关闭了Swizzling,必须手动转发通知:

  • 开启Swizzling(默认):确认Info.plist中没有FirebaseAppDelegateProxyEnabled键,或者该键值设为YES。
  • 关闭Swizzling:在AppDelegate的推送回调方法中添加Firebase Auth的处理逻辑:
    // iOS 13+ 异步回调方法
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) async -> UIBackgroundFetchResult {
        if Auth.auth().canHandleNotification(userInfo) {
            return .noData
        }
        // 你的其他推送处理逻辑
        return .noData
    }
    
    // 兼容iOS 10及以下的回调方法
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        if Auth.auth().canHandleNotification(userInfo) {
            completionHandler(.noData)
            return
        }
        // 你的其他推送处理逻辑
        completionHandler(.noData)
    }
    
    注意:即使普通推送能触发这些方法,也要确保Auth.auth().canHandleNotification(userInfo)优先被调用,认证推送的payload有特殊标识,必须由Firebase处理。

2. 确认推送权限与后台配置

  • 除了Signing and Capabilities中的Push Notifications,必须开启Background Modes下的Remote notifications选项,否则App在后台无法接收认证推送。
  • 检查用户是否授权了推送权限:
    UNUserNotificationCenter.current().getNotificationSettings { settings in
        if settings.authorizationStatus != .authorized {
            // 引导用户开启推送权限
        }
    }
    

3. 校验Firebase配置一致性

  • 确认Firebase控制台中上传的APNs密钥对应当前运行环境(开发用Sandbox,生产用Production),且Bundle ID与App完全匹配。
  • 重新下载最新的GoogleService-Info.plist替换到项目中,确保里面的GCM_SENDER_ID等推送相关配置正确。
  • 检查Xcode的Build Settings中,PROVISIONING_PROFILE对应的证书包含推送权限。

4. 修正手机号认证调用逻辑

  • 确保传入verifyPhoneNumber的手机号是E.164标准格式(例如+8613800000000),格式错误会导致Firebase无法下发验证码推送。
  • 手动同步APNs Token到Firebase(部分设备可能需要手动触发):
    Messaging.messaging().token { token, error in
        guard let token = token else { return }
        let tokenData = token.data(using: .utf8)!
        // 根据环境切换type:.sandbox或.production
        Auth.auth().setAPNSToken(tokenData, type: .sandbox)
    }
    

5. 测试环境特殊排查

  • 测试设备不要开启“请勿打扰”模式,确保网络通畅(Firebase需要通过APNs下发推送,网络不稳定会导致失败)。
  • 卸载重装App,清除旧的推送Token缓存。
  • 查看Xcode控制台的APNs相关日志,排查是否有推送被拒绝、Token无效等报错信息。

内容的提问来源于stack exchange,提问作者Dan Micsa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 08:44:50