Facebook登录错误 - 构建URL时出现未知错误(com.facebook.sdk.core错误3)

Vin*_*nzo 14 google-login ios facebook-login swift

我在尝试使用Facebook登录时遇到此错误: Optional(Error Domain=com.facebook.sdk.core Code=3 "(null)" UserInfo={com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Unknown error building URL.}) 我在其他帖子中读到这是一个错误,版本是4.39.0版本的FBSDKLoginKit,解决方案正在降级到4.38.o现在这给了我另一个错误:Firebase Auth Interop/FIRAuth Interop.h' file not found in the FIRAuth.m #import <FirebaseAuthInterop/FIRAuthInterop.h> 因为我是新的社交登录和Facebook开发者页面中的指南不是最新的swift和一些是obj-c我可能误解为swift.你能发现问题出在哪里吗?此外,FBSDKLogin框架在frameworks文件夹中以红色突出显示,并且pods/Frameworks文件夹中的所有框架都以突出显示.这是代码:AppDelegate

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: ({_,_ in
        }))

        UNUserNotificationCenter.current().delegate = self

        var error: NSError?
        do {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        } catch let error1 as NSError{
            error = error1
            print("could not set session. err:\(error!.localizedDescription)")
        }
        do {
            try AVAudioSession.sharedInstance().setActive(true)
        } catch let error1 as NSError{
            error = error1
            print("could not active session. err:\(error!.localizedDescription)")
        }
        window?.tintColor = UIColor.blue

        // Use Firebase library to configure APIs
        FirebaseApp.configure()

        // goggle only
        GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
        GIDSignIn.sharedInstance().delegate = self

        // Facebook SDK
//        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)


//        return true
    }
Run Code Online (Sandbox Code Playgroud)

我将谷歌登录和Facebook的开放URL:

// start google sign in methods
    @available(iOS 9.0, *)
    func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
        -> Bool {
            // google only
//            return
//                GIDSignIn.sharedInstance().handle(url,
//                                                     sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
//                                                     annotation: options[UIApplicationOpenURLOptionsKey.annotation])

            // both google and facebook

            let googleDidHandle = GIDSignIn.sharedInstance().handle(url,
                                                                       sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                                       annotation: options[UIApplicationOpenURLOptionsKey.annotation])


            guard let source = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String else { return false }
            let annotation = options[UIApplicationOpenURLOptionsKey.annotation] as? String

            let facebookDidHandle =  FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: source, annotation: annotation)



//            return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: source, annotation: annotation)



            return googleDidHandle || facebookDidHandle
    }
Run Code Online (Sandbox Code Playgroud)

使用Facebook方法登录vc,我收到错误:

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
    if error == nil {
        print("User just logged in via Facebook")
        let credentials = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
        Auth.auth().signInAndRetrieveData(with: credentials) { (user, error) in
            if (error != nil) {
                print("Facebook authentication failed")
            } else {
                print("Facebook authentication succeed")
            }
        }//)
    } else {
        print("An error occured the user couldn't log in")
        print(error)
    }
}
Run Code Online (Sandbox Code Playgroud)

Vin*_*nzo 15

我发现了这个问题.这与代码无关.这似乎是Facebook SDK的最新两个版本中的一个错误,因此我将其降级为

pod 'FBSDKCoreKit', '4.36.0'  
pod 'FBSDKLoginKit', '4.36.0'  
pod 'FacebookCore', '0.4'  
pod 'FacebookLogin', '0.4'
Run Code Online (Sandbox Code Playgroud)

它运行顺利.某人4.38版的面团解决了这个问题,它不适合我.希望这对其他人有用.


sha*_*zar 9

这是版本4.39.0中的Facebook SDK错误,导致此错误.为了解决这个问题,只需将CoreKit和LoginKit降级到4.38.0,清除派生数据以及清理构建文件夹(CMD + OPTION + SHIFT + K).

pod 'FBSDKCoreKit', '~> 4.38.0'
pod 'FBSDKLoginKit', '~> 4.38.0'
Run Code Online (Sandbox Code Playgroud)

如果您使用的是FacebookCore和FacebookLogin,请执行以下操作.

pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FBSDKCoreKit', '~> 4.38.0'
pod 'FBSDKLoginKit', '~> 4.38.0'
Run Code Online (Sandbox Code Playgroud)