Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <GooglePlus/GooglePlus.h>
- #import "AppDelegate.h"
- @interface AppDelegate ()
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- return YES;
- }
- - (void)applicationWillResignActive:(UIApplication *)application {
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application {
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- }
- - (BOOL)application: (UIApplication *)application
- openURL: (NSURL *)url
- sourceApplication: (NSString *)sourceApplication
- annotation: (id)annotation {
- return [GPPURLHandler handleURL:url
- sourceApplication:sourceApplication
- annotation:annotation];
- }
- #import <UIKit/UIKit.h>
- #import <GooglePlus/GooglePlus.h>
- @class GPPSignInButton;
- @interface ViewController : UIViewController<GPPSignInDelegate>
- @property (strong, nonatomic) IBOutlet GPPSignInButton *signInButton;
- @end
- //
- #import <GooglePlus/GooglePlus.h>
- #import "ViewController.h"
- #import <GoogleOpenSource/GoogleOpenSource.h>
- #define kClientId @"49781846815-pbsb1vso4nrbes9a4al5kae2d98ie3cf.apps.googleusercontent.com"
- #define kGTLAuthScopePlusLogin @"https://www.googleapis.com/auth/plus.login"
- @interface ViewController ()
- @end
- @implementation ViewController
- @synthesize signInButton;
- - (void)viewDidLoad {
- [super viewDidLoad];
- GPPSignIn *signIn = [GPPSignIn sharedInstance];
- // Do any additional setup after loading the view, typically from a nib.
- signIn.shouldFetchGooglePlusUser = YES;
- signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user's email
- // You previously set kClientId in the "Initialize the Google+ client" step
- signIn.clientID = kClientId;
- // Uncomment one of these two statements for the scope you chose in the previous step
- signIn.scopes = @[ kGTLAuthScopePlusLogin ]; // "https://www.googleapis.com/auth/plus.login" scope
- signIn.scopes = @[ @"profile" ]; // "profile" scope
- // Optional: declare signIn.actions, see "app activities"
- signIn.delegate = self;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
- error: (NSError *) error {
- NSLog(@"Received error %@ and auth object %@",error, auth);
- if (error) {
- // Do some error handling here.
- } else {
- [self refreshInterfaceBasedOnSignIn];
- }
- }
- -(void)refreshInterfaceBasedOnSignIn {
- if ([[GPPSignIn sharedInstance] authentication]) {
- // The user is signed in.
- NSLog(@"hi");
- self.signInButton.hidden = YES;
- // Perform other actions here, such as showing a sign-out button
- } else {
- self.signInButton.hidden = NO;
- // Perform other actions here
- }
- }
- - (void)presentSignInViewController:(UIViewController *)viewController {
- // This is an example of how you can implement it if your app is navigation-based.
- [[self navigationController] pushViewController:viewController animated:YES];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement