Dumped Google+ SDK.
[UPDATED] Google+ SDK.
This commit is contained in:
@@ -19,22 +19,13 @@
|
||||
#import "GooglePlusSampleSignInViewController.h"
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import "GooglePlusSampleAppDelegate.h"
|
||||
#import "GPPSignIn.h"
|
||||
#import "GPPSignInButton.h"
|
||||
#import "GTLPlus.h"
|
||||
#import "GTLPlusConstants.h"
|
||||
#import "GTLQueryPlus.h"
|
||||
#import "GTLServicePlus.h"
|
||||
#import "GTMLogger.h"
|
||||
#import "GTMOAuth2Authentication.h"
|
||||
|
||||
@interface GooglePlusSampleSignInViewController () {
|
||||
// Saved state of |userinfoEmailScope_.on|.
|
||||
BOOL savedUserinfoEmailScopeState_;
|
||||
}
|
||||
- (GooglePlusSampleAppDelegate *)appDelegate;
|
||||
- (void)setSignInScopes;
|
||||
@interface GooglePlusSampleSignInViewController ()
|
||||
- (void)enableSignInSettings:(BOOL)enable;
|
||||
- (void)reportAuthStatus;
|
||||
- (void)retrieveUserInfo;
|
||||
@@ -46,7 +37,7 @@
|
||||
@synthesize signInAuthStatus = signInAuthStatus_;
|
||||
@synthesize signInDisplayName = signInDisplayName_;
|
||||
@synthesize signOutButton = signOutButton_;
|
||||
@synthesize plusMomentsWriteScope = plusMomentsWriteScope_;
|
||||
@synthesize disconnectButton = disconnectButton_;
|
||||
@synthesize userinfoEmailScope = userinfoEmailScope_;
|
||||
|
||||
- (void)dealloc {
|
||||
@@ -54,44 +45,52 @@
|
||||
[signInAuthStatus_ release];
|
||||
[signInDisplayName_ release];
|
||||
[signOutButton_ release];
|
||||
[userinfoEmailScope_ release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark - View lifecycle
|
||||
|
||||
- (void)viewDidLoad {
|
||||
GooglePlusSampleAppDelegate *appDelegate = [self appDelegate];
|
||||
plusMomentsWriteScope_.on = appDelegate.plusMomentsWriteScope;
|
||||
userinfoEmailScope_.on = savedUserinfoEmailScopeState_;
|
||||
// Make sure the GPPSignInButton class is linked in because references from
|
||||
// xib file doesn't count.
|
||||
[GPPSignInButton class];
|
||||
|
||||
// Set up sign-out button.
|
||||
[[signOutButton_ layer] setCornerRadius:5];
|
||||
[[signOutButton_ layer] setMasksToBounds:YES];
|
||||
CGColorRef borderColor = [[UIColor colorWithWhite:203.0/255.0
|
||||
alpha:1.0] CGColor];
|
||||
[[signOutButton_ layer] setBorderColor:borderColor];
|
||||
[[signOutButton_ layer] setBorderWidth:1.0];
|
||||
GPPSignIn *signIn = [GPPSignIn sharedInstance];
|
||||
userinfoEmailScope_.on =
|
||||
signIn.shouldFetchGoogleUserEmail;
|
||||
|
||||
// Set up sign-out and disconnect buttons.
|
||||
[self setUpButton:signOutButton_];
|
||||
[self setUpButton:disconnectButton_];
|
||||
|
||||
// Set up sample view of Google+ sign-in.
|
||||
signInButton_.delegate = self;
|
||||
signInButton_.shouldFetchGoogleUserEmail = userinfoEmailScope_.on;
|
||||
signInButton_.clientID = [GooglePlusSampleAppDelegate clientID];
|
||||
[self setSignInScopes];
|
||||
// The client ID has been set in the app delegate.
|
||||
signIn.delegate = self;
|
||||
signIn.shouldFetchGoogleUserEmail = userinfoEmailScope_.on;
|
||||
signIn.actions = [NSArray arrayWithObjects:
|
||||
@"http://schemas.google.com/AddActivity",
|
||||
@"http://schemas.google.com/BuyActivity",
|
||||
@"http://schemas.google.com/CheckInActivity",
|
||||
@"http://schemas.google.com/CommentActivity",
|
||||
@"http://schemas.google.com/CreateActivity",
|
||||
@"http://schemas.google.com/ListenActivity",
|
||||
@"http://schemas.google.com/ReserveActivity",
|
||||
@"http://schemas.google.com/ReviewActivity",
|
||||
nil];
|
||||
|
||||
appDelegate.signInButton = signInButton_;
|
||||
[self reportAuthStatus];
|
||||
[signIn trySilentAuthentication];
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
GooglePlusSampleAppDelegate *appDelegate = [self appDelegate];
|
||||
appDelegate.plusMomentsWriteScope = plusMomentsWriteScope_.on;
|
||||
savedUserinfoEmailScopeState_ = userinfoEmailScope_.on;
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
GooglePlusSampleAppDelegate *appDelegate = [self appDelegate];
|
||||
appDelegate.signInButton = nil;
|
||||
[self setSignInButton:nil];
|
||||
[self setSignInAuthStatus:nil];
|
||||
[self setSignInDisplayName:nil];
|
||||
[self setSignOutButton:nil];
|
||||
[self setDisconnectButton:nil];
|
||||
[self setUserinfoEmailScope:nil];
|
||||
[super viewDidUnload];
|
||||
}
|
||||
|
||||
@@ -104,37 +103,38 @@
|
||||
[NSString stringWithFormat:@"Status: Authentication error: %@", error];
|
||||
return;
|
||||
}
|
||||
GooglePlusSampleAppDelegate *appDelegate = [self appDelegate];
|
||||
appDelegate.auth = auth;
|
||||
[self reportAuthStatus];
|
||||
}
|
||||
|
||||
- (void)didDisconnectWithError:(NSError *)error {
|
||||
if (error) {
|
||||
signInAuthStatus_.text =
|
||||
[NSString stringWithFormat:@"Status: Failed to disconnect: %@", error];
|
||||
} else {
|
||||
signInAuthStatus_.text =
|
||||
[NSString stringWithFormat:@"Status: Disconnected"];
|
||||
signInDisplayName_.text = @"";
|
||||
[self enableSignInSettings:YES];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Helper methods
|
||||
|
||||
- (GooglePlusSampleAppDelegate *)appDelegate {
|
||||
return (GooglePlusSampleAppDelegate *)
|
||||
[[UIApplication sharedApplication] delegate];
|
||||
}
|
||||
|
||||
- (void)setSignInScopes {
|
||||
signInButton_.scope = plusMomentsWriteScope_.on ?
|
||||
[NSArray arrayWithObjects:
|
||||
@"https://www.googleapis.com/auth/plus.moments.write",
|
||||
@"https://www.googleapis.com/auth/plus.me",
|
||||
nil] :
|
||||
[NSArray arrayWithObjects:
|
||||
@"https://www.googleapis.com/auth/plus.me",
|
||||
nil];
|
||||
- (void)setUpButton:(UIButton *)button {
|
||||
[[button layer] setCornerRadius:5];
|
||||
[[button layer] setMasksToBounds:YES];
|
||||
CGColorRef borderColor = [[UIColor colorWithWhite:203.0/255.0
|
||||
alpha:1.0] CGColor];
|
||||
[[button layer] setBorderColor:borderColor];
|
||||
[[button layer] setBorderWidth:1.0];
|
||||
}
|
||||
|
||||
- (void)enableSignInSettings:(BOOL)enable {
|
||||
plusMomentsWriteScope_.enabled = enable;
|
||||
userinfoEmailScope_.enabled = enable && !plusMomentsWriteScope_.on;
|
||||
userinfoEmailScope_.enabled = enable;
|
||||
}
|
||||
|
||||
- (void)reportAuthStatus {
|
||||
GooglePlusSampleAppDelegate *appDelegate = [self appDelegate];
|
||||
if (appDelegate.auth) {
|
||||
if ([GPPSignIn sharedInstance].authentication) {
|
||||
signInAuthStatus_.text = @"Status: Authenticated";
|
||||
[self retrieveUserInfo];
|
||||
[self enableSignInSettings:NO];
|
||||
@@ -146,36 +146,26 @@
|
||||
}
|
||||
|
||||
- (void)retrieveUserInfo {
|
||||
GooglePlusSampleAppDelegate *appDelegate = [self appDelegate];
|
||||
if (appDelegate.auth.userEmail) {
|
||||
signInDisplayName_.text = appDelegate.auth.userEmail;
|
||||
} else {
|
||||
signInDisplayName_.text = @"";
|
||||
}
|
||||
signInDisplayName_.text = [NSString stringWithFormat:@"Email: %@",
|
||||
[GPPSignIn sharedInstance].authentication.userEmail];
|
||||
}
|
||||
|
||||
#pragma mark - IBActions
|
||||
|
||||
- (IBAction)signOut:(id)sender {
|
||||
[[signInButton_ googlePlusSignIn] signOut];
|
||||
|
||||
GooglePlusSampleAppDelegate *appDelegate = [self appDelegate];
|
||||
appDelegate.auth = nil;
|
||||
[[GPPSignIn sharedInstance] signOut];
|
||||
|
||||
[self reportAuthStatus];
|
||||
signInDisplayName_.text = @"";
|
||||
}
|
||||
|
||||
- (IBAction)plusMomentsWriteScopeToggle:(id)sender {
|
||||
[self setSignInScopes];
|
||||
userinfoEmailScope_.enabled = !plusMomentsWriteScope_.on;
|
||||
if (plusMomentsWriteScope_.on) {
|
||||
userinfoEmailScope_.on = NO;
|
||||
}
|
||||
- (IBAction)disconnect:(id)sender {
|
||||
[[GPPSignIn sharedInstance] disconnect];
|
||||
}
|
||||
|
||||
- (IBAction)userinfoEmailScopeToggle:(id)sender {
|
||||
signInButton_.shouldFetchGoogleUserEmail = userinfoEmailScope_.on;
|
||||
[GPPSignIn sharedInstance].shouldFetchGoogleUserEmail =
|
||||
userinfoEmailScope_.on;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user