Last active
June 24, 2018 06:16
-
-
Save MartinP7r/1999daab25c23b5440dc24839ff3f653 to your computer and use it in GitHub Desktop.
medium_post_05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GoogleSignInService: NSObject, SignInService, GIDSignInDelegate, GIDSignInUIDelegate { | |
// intermediary closure to be called when sign-in finishes | |
var signedIn: ((String) -> Void)? | |
func setup() { /* (...) */ } | |
func signIn(_ completion: @escaping (String) -> Void) { | |
// hand own completion block to intermediary closure | |
signedIn = { token in | |
completion(token) | |
} | |
GIDSignIn.sharedInstance().signIn() | |
} | |
func sign(_ signIn: GIDSignIn!, | |
didSignInFor user: GIDGoogleUser!, | |
withError error: Error!) { | |
if let error == nil { | |
// call intermediary closure with token | |
signedIn?(user.authentication.idToken) | |
} | |
} | |
func signOut() { /* (...) */ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment