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

时间:2018-12-11 22:24:55

标签: ios swift facebook-login google-login

尝试使用Facebook登录时出现此错误: Optional(Error Domain=com.facebook.sdk.core Code=3 "(null)" UserInfo={com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Unknown error building URL.}) 我在其他帖子中读到,这是FBSDKLoginKit版本4.39.0中的错误,解决方案降级到4.38.o现在,这给了我另一个错误:Firebase Auth Interop/FIRAuth Interop.h' file not found in the FIRAuth.m #import <FirebaseAuthInterop/FIRAuthInterop.h> 由于我是社交登录的新手,并且Facebook开发人员页面中的指南不是最新的,而其中的一些内容已包含在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
    }

我同时登录Google和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
    }

使用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)
    }
}

4 个答案:

答案 0 :(得分:15)

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

package.json

,运行平稳。 适用于4.38版的人的面团解决了这个问题,但对我而言,这并不是汽车。 希望这对其他人有用。

答案 1 :(得分: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'

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

pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FBSDKCoreKit', '~> 4.38.0'
pod 'FBSDKLoginKit', '~> 4.38.0'

答案 2 :(得分:2)

该4.39.1似乎有一个热修复程序,于2019年1月15日发布(显然是未来一周)

https://developers.facebook.com/docs/ios/change-log-4x/

答案 3 :(得分:0)

此GitHub上的解决方法对我有用:

https://github.com/facebook/facebook-swift-sdk/issues/301#issuecomment-446363750

还有其他一些适用于其他人的变通办法。

我的pod文件在工作时看起来像这样:

pod 'FBSDKCoreKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'