Trouble handling Google sign in Swift 3

前端 未结 5 1650
花落未央
花落未央 2021-01-06 02:30

I am new to iOS and am having trouble with app delegate URL handling in Swift 3, and I could really use some pointers.

The below code works perfectly fine in Swift 2

5条回答
  •  执念已碎
    2021-01-06 02:41

    Try to perform any operations at function "signIn" in AppDelegate.

    After Google sends you some data:

    func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
                withError error: NSError!) {
    
        if (error == nil) {
            // Perform any operations on signed in user here.
            let userId = user.userID
            // Perform some operation to change the scene.
            // ........
    
        }
        else {
            print("\(error.localizedDescription)")
        }
    }
    

    Maybe the code below can give you some idea:

    let myStoryBoard:UIStoryboard = UIStoryboard(name:"Main", bundle:nil)
    
    let protectedPage = myStoryBoard.instantiateViewControllerWithIdentifier("ProtectedPageViewController") as! ProtectedPageViewController
    
    let protectedPageNav = UINavigationController(rootViewController: protectedPage)
    
    let appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    
    appDelegate.window?.rootViewController = protectedPageNav
    

    ??? I reference from YouTube's video "Sign-in with Google Account button. Example in Swift. Video 2", that are provided from "Sergey Kargopolov".

    and...

    I have a question similar to this and didn't solve it...

    Good luck! :)

提交回复
热议问题