Skip to content

Instantly share code, notes, and snippets.

@SotoiGhost
Created November 24, 2017 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SotoiGhost/61c3bbf5256616b768d81133cfeb62d9 to your computer and use it in GitHub Desktop.
Save SotoiGhost/61c3bbf5256616b768d81133cfeb62d9 to your computer and use it in GitHub Desktop.
Use of ISignInDelegate interface
public partial class ViewController : UIViewController, ISignInUIDelegate, ISignInDelegate
{
public ViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// TODO(developer) Configure the sign-in button look/feel
SignIn.SharedInstance.Delegate = this;
SignIn.SharedInstance.UIDelegate = this;
// Automatically sign in the user.
SignIn.SharedInstance.SignInUserSilently ();
ToggleAuthUI ();
statusText.Text = "Google Sign in\niOS Demo";
}
partial void didTapSignOut (NSObject sender)
{
SignIn.SharedInstance.SignOutUser ();
ToggleAuthUI ();
}
partial void didTapDisconnect (NSObject sender)
{
SignIn.SharedInstance.DisconnectUser ();
}
void ToggleAuthUI ()
{
if (SignIn.SharedInstance.CurrentUser == null || SignIn.SharedInstance.CurrentUser.Authentication == null) {
// Not signed in
statusText.Text = "Google Sign in\niOS Demo";
signInButton.Hidden = false;
signOutButton.Hidden = true;
disconnectButton.Hidden = true;
} else {
// Signed in
signInButton.Hidden = true;
signOutButton.Hidden = false;
disconnectButton.Hidden = false;
}
}
public override UIStatusBarStyle PreferredStatusBarStyle ()
{
return UIStatusBarStyle.LightContent;
}
#region Sign In Delegate
public void DidSignIn (SignIn signIn, GoogleUser user, NSError error)
{
if (user != null && error == null) {
statusText.Text = string.Format ("Signed in user: {0}", user.Profile.Name);
ToggleAuthUI ();
}
}
[Export ("signIn:didDisconnectWithUser:withError:")]
public void DidDisconnect (SignIn signIn, GoogleUser user, NSError error)
{
statusText.Text = "Disconnected user";
ToggleAuthUI ();
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment