// AppDelegate.m-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{// Override point for customization after application launch.NSError*configureError;[[GGLContextsharedInstance]configureWithError:&configureError];NSAssert(!configureError,@"Error configuring Google services: %@",configureError);[GIDSignInsharedInstance].delegate=self;returnYES;}<省略>-(BOOL)application:(UIApplication*)applicationopenURL:(NSURL*)urlsourceApplication:(NSString*)sourceApplicationannotation:(id)annotation{return[[GIDSignInsharedInstance]handleURL:urlsourceApplication:sourceApplicationannotation:annotation];}// Google Sign-inに成功した場合に呼び出される処理-(void)signIn:(GIDSignIn*)signIndidSignInForUser:(GIDGoogleUser*)userwithError:(NSError*)error{// Perform any operations on signed in user here.NSString*userId=user.userID;// For client-side use only!NSString*idToken=user.authentication.idToken;// Safe to send to the serverNSString*name=user.profile.name;NSString*email=user.profile.email;NSLog(@"userId: %@, idToken: %@, name: %@, email: %@",userId,idToken,name,email);}// Google Sign-inに失敗した場合に呼び出される処理-(void)signIn:(GIDSignIn*)signIndidDisconnectWithUser:(GIDGoogleUser*)userwithError:(NSError*)error{// Perform any operations when the user disconnects from app here.NSLog(@"error: %@",error);}
// ViewController.m-(void)viewDidLoad{[superviewDidLoad];// Do any additional setup after loading the view, typically from a nib.[GIDSignInsharedInstance].uiDelegate=self;// 任意のスコープを設定[GIDSignInsharedInstance].scopes=@[@"https://www.googleapis.com/auth/calendar",@"https://www.googleapis.com/auth/drive"];NSLog(@"scope: %@",[GIDSignInsharedInstance].scopes);}// エラーが発生した場合に呼び出される処理-(void)signInWillDispatch:(GIDSignIn*)signInerror:(NSError*)error{NSLog(@"error: %@",error);}// Google OAuth2認証画面を開始するときに実行される処理-(void)signIn:(GIDSignIn*)signInpresentViewController:(UIViewController*)viewController{// OAuth2認証画面を表示する処理[selfpresentViewController:viewControlleranimated:YEScompletion:nil];}// Google OAuth2認証が完了したら実行される処理-(void)signIn:(GIDSignIn*)signIndismissViewController:(UIViewController*)viewController{// OAuth2認証の画面を閉じる処理[selfdismissViewControllerAnimated:YEScompletion:nil];}// Google Sign-inボタンをクリックした場合の処理(Storyboardで設定すること)-(IBAction)didTapSignIn:(id)sender{// Google Sign-inを実行する処理[[GIDSignInsharedInstance]signIn];}