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

iOS端Facebook Limited Login生产用户无法登录,求确认Published与Live状态

Facebook Limited Login 登录问题排查与解决

背景

  • 长时间未发布支持Facebook登录的应用,不确定Published状态是否与Live状态一致,求确认。
  • 近期将Facebook登录升级为Facebook Limited Login(SDK v17.0.1),升级前经典Facebook登录在开发模式下运行正常。
  • 当前问题:iOS 17.4.1测试环境下无法完成登录,要么无法获取AuthenticationToken,要么返回cancelled状态。

登录流程代码

生成LoginConfiguration实例

let rawNonce = String.randomNonceString()
let sha256Nonce = rawNonce.sha256
let config = LoginConfiguration(permissions: ["public_profile", "email"], tracking: .enabled, nonce: sha256Nonce)!

执行登录逻辑

let loginManager = FacebookLogin.LoginManager()
loginManager.logIn(viewController: viewController, configuration: configuration) { result in
    switch result {
        case .success(let grantedPermissions, let declinedPermissions, let token):
            let authTokenString = AuthenticationToken.current?.tokenString
            // 使用authTokenString和rawNonce创建Firebase Auth凭证

        case .cancelled:
            // 用户取消登录

        case .failed(let error):
            print(error)
    }
}

问题现象

  1. 拥有Facebook应用角色的用户,登录全程正常。
  2. 无应用角色的生产用户登录失败,分为两种场景:
    • 场景A:当LoginConfiguration中tracking设置为.enabled时,登录回调返回.success,但AuthenticationToken.current为nil。
    • 场景B:当LoginConfiguration中tracking设置为.limited时,登录回调直接返回.cancelled,结果不符合预期。

已尝试的排查方案

  • 登录前提前启用App Tracking Transparency,问题未解决。
  • 按文档要求应使用全局AuthenticationToken而非登录回调返回的AccessToken,但尝试用AccessToken创建Firebase Auth凭证时,提示错误Bad access token。
  • 尝试每隔0.5秒轮询获取AuthenticationToken直至非空,无效果。
  • 模拟器与真机均进行测试,问题表现一致。

更新与结论

随机数生成及SHA256实现代码

public extension String {
    
    static func randomNonceString(length: Int = 32) -> String {
        precondition(length > 0)
        var randomBytes = [UInt8](repeating: 0, count: length)
        let errorCode = SecRandomCopyBytes(kSecRandomDefault, randomBytes.count, &randomBytes)
        if errorCode != errSecSuccess {
            fatalError(
                "Unable to generate nonce. OSStatus \(errorCode)"
            )
        }
        
        let charset: [Character] = Array("0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._")
        
        let nonce = randomBytes.map { byte in
            charset[Int(byte) % charset.count]
        }
        
        return String(nonce)
    }
    
    var sha256: String {
        let inputData = Data(self.utf8)
        let hashedData = SHA256.hash(data: inputData)
        let hashString = hashedData.compactMap { String(format: "%02x", $0) }.joined()
        return hashString
    }
}

2024年7月3日未修改代码再次测试,登录功能恢复正常。推测原问题为Facebook发布Limited Login时的后端临时故障,相关Github Issue显示有其他开发者也遇到了相同问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 16:53:14