简体   繁体   中英

iOS : App freezes with facebook sdk and google sign in

I am trying to allow user login with facebook , twitter and google . My application is old and converted from swift 3 to swift 5 . Twitter login works properly but Facebook login and Google login not work , App freezes and the screen blurs without errors like this https://youtu.be/oT4i8Es0cdI

I tried the same code with new project and it works properly . What makes old converted apps doesn't work with the same code.

I am using facebook sdk : 5.15.1 Xcode 13.3.1 Swift 5

Code In app delegate open url:

        _ app: UIApplication,
        open url: URL,
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]
    ) -> Bool {
        print("App open url")
        let googleDidHandle = GIDSignIn.sharedInstance().handle(url)
        let twitterHandle = TWTRTwitter.sharedInstance().application(app, open: url, options: options)
        let facebookDidHandle = ApplicationDelegate.shared.application(
            app,
            open: url,
            options: options)


        return twitterHandle || facebookDidHandle || googleDidHandle

    }
**Code for login :**
 @IBAction func loginWithFacebbok(_ sender: UIButton) {
        add(loadingViewController)

        let loginManager = FBSDKLoginKit.LoginManager()

        loginManager.logIn(permissions: [ "email"], from: self) { (result, error) in
            if error == nil{
                print("get facebook data")
                self.getFacebookData(accessToken: result?.token)

            }else{
                print("error is \(error)")
            }
        }


    }


@IBAction func loginWithGmail(_ sender: UIButton) {
        //GIDSignIn.sharedInstance()?.delegate = self
        add(loadingViewController)

        GIDSignIn.sharedInstance().signIn()
    }
override func viewDidLoad() {
        super.viewDidLoad()
        GIDSignIn.sharedInstance()?.presentingViewController = self
}
in App delegate
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()

        GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
        GIDSignIn.sharedInstance().delegate = self
LanguageHelper.setSavedLanguage()
        ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )
        return true

}```

I found the answer. The problem was in Xcode version. After updating to 13.4 everything is OK. Just try to update your Xcode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM