Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #import <GooglePlus/GooglePlus.h>
  2. #import "AppDelegate.h"
  3.  
  4. @interface AppDelegate ()
  5.  
  6. @end
  7.  
  8. @implementation AppDelegate
  9.  
  10.  
  11. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  12. // Override point for customization after application launch.
  13. return YES;
  14. }
  15.  
  16. - (void)applicationWillResignActive:(UIApplication *)application {
  17. // 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.
  18. // 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.
  19. }
  20.  
  21. - (void)applicationDidEnterBackground:(UIApplication *)application {
  22. // 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.
  23. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  24. }
  25. - (BOOL)application: (UIApplication *)application
  26. openURL: (NSURL *)url
  27. sourceApplication: (NSString *)sourceApplication
  28. annotation: (id)annotation {
  29. return [GPPURLHandler handleURL:url
  30. sourceApplication:sourceApplication
  31. annotation:annotation];
  32. }
  33.  
  34. #import <UIKit/UIKit.h>
  35. #import <GooglePlus/GooglePlus.h>
  36. @class GPPSignInButton;
  37. @interface ViewController : UIViewController<GPPSignInDelegate>
  38.  
  39. @property (strong, nonatomic) IBOutlet GPPSignInButton *signInButton;
  40.  
  41. @end
  42.  
  43. //
  44. #import <GooglePlus/GooglePlus.h>
  45.  
  46. #import "ViewController.h"
  47. #import <GoogleOpenSource/GoogleOpenSource.h>
  48. #define kClientId @"49781846815-pbsb1vso4nrbes9a4al5kae2d98ie3cf.apps.googleusercontent.com"
  49. #define kGTLAuthScopePlusLogin @"https://www.googleapis.com/auth/plus.login"
  50. @interface ViewController ()
  51.  
  52. @end
  53.  
  54. @implementation ViewController
  55. @synthesize signInButton;
  56.  
  57. - (void)viewDidLoad {
  58. [super viewDidLoad];
  59. GPPSignIn *signIn = [GPPSignIn sharedInstance];
  60.  
  61. // Do any additional setup after loading the view, typically from a nib.
  62. signIn.shouldFetchGooglePlusUser = YES;
  63. signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user's email
  64.  
  65. // You previously set kClientId in the "Initialize the Google+ client" step
  66. signIn.clientID = kClientId;
  67.  
  68. // Uncomment one of these two statements for the scope you chose in the previous step
  69. signIn.scopes = @[ kGTLAuthScopePlusLogin ]; // "https://www.googleapis.com/auth/plus.login" scope
  70. signIn.scopes = @[ @"profile" ]; // "profile" scope
  71.  
  72. // Optional: declare signIn.actions, see "app activities"
  73. signIn.delegate = self;
  74.  
  75. }
  76.  
  77. - (void)didReceiveMemoryWarning {
  78. [super didReceiveMemoryWarning];
  79. // Dispose of any resources that can be recreated.
  80. }
  81. - (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
  82. error: (NSError *) error {
  83. NSLog(@"Received error %@ and auth object %@",error, auth);
  84. if (error) {
  85. // Do some error handling here.
  86. } else {
  87. [self refreshInterfaceBasedOnSignIn];
  88. }
  89. }
  90. -(void)refreshInterfaceBasedOnSignIn {
  91. if ([[GPPSignIn sharedInstance] authentication]) {
  92. // The user is signed in.
  93. NSLog(@"hi");
  94. self.signInButton.hidden = YES;
  95. // Perform other actions here, such as showing a sign-out button
  96. } else {
  97. self.signInButton.hidden = NO;
  98. // Perform other actions here
  99. }
  100. }
  101.  
  102. - (void)presentSignInViewController:(UIViewController *)viewController {
  103. // This is an example of how you can implement it if your app is navigation-based.
  104. [[self navigationController] pushViewController:viewController animated:YES];
  105. }
  106. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement