Updated 14 December 2016
1: There are two ways to Integrate the Application with google sign in. (Using cocoa pod and manual);
2: Here I am mentioning manual way.
3: Download the Google SDK from that site. (https://developers.google.com/identity/sign-in/ios/sdk/)
4: Extract the SDK archive you downloaded and copy the following files to your Xcode project:
GoogleSignIn.framework
GoogleSignIn.bundle
GoogleSignIn.bundle
to your Xcode project’s Copy Bundle Resources build phase.5: Link the dependent framework in Xcode.
AddressBook.framework
SafariServices.framework
SystemConfiguration.framework
6: set other linker flags in build setting
$(OTHER_LDFLAGS) -ObjC
7: Get the Configuration file by clicking that URL : (https://developers.google.com/mobile/)
8: Enter App name and bundle Id so it will create .plist file so you have to drag into your xcode as root.
9: add the following Data :
Also, you will need to set the client ID directly using the value found in the GoogleService-Info.plist
file:
1 2 |
<span class="pun">[</span><span class="typ">GIDSignIn</span><span class="pln"> sharedInstance</span><span class="pun">].</span><span class="pln">clientID </span><span class="pun">=</span><span class="pln"> kClientID</span><span class="pun">;</span> |
10 : Do some changes in App delegate file :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#import "AppDelegate.h" #import <GoogleSignIn/GoogleSignIn.h> @interface AppDelegate () @end @implementation AppDelegate static NSString * const kClientID = @"442678058869-fto2clbuonqr1au1laa2u23fnji0h454.apps.googleusercontent.com"; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [GIDSignIn sharedInstance].clientID = kClientID; return YES; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [[GIDSignIn sharedInstance] handleURL:url sourceApplication:sourceApplication annotation:annotation]; } |
here kClientId is client id of generated configuration .plist file.
11: Now to draw the google sign in button so here I am taking a view controller to display all that things.
a: viewcontroller.m class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
// // ViewController.m // DummyGoogleSignIn // // Created by kunal prasad on 12/09/16. // Copyright © 2016 Webkul. All rights reserved. // #import "ViewController.h" #import <GoogleSignIn/GoogleSignIn.h> @interface ViewController () <GIDSignInDelegate, GIDSignInUIDelegate> @property (nonatomic, copy) void (^confirmActionBlock)(void); @property (nonatomic, copy) void (^cancelActionBlock)(void); @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GIDSignInButton *polygonView = [[GIDSignInButton alloc] initWithFrame: CGRectMake ( 20, 200, 120, 50)]; polygonView.backgroundColor = [UIColor clearColor]; [_mainView addSubview:polygonView]; [GIDSignInButton class]; GIDSignIn *signIn = [GIDSignIn sharedInstance]; signIn.shouldFetchBasicProfile = YES; signIn.delegate = self; signIn.uiDelegate = self; } #pragma mark - GIDSignInDelegate - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error { NSLog(@"gfklghfghfghf "); if (error) { NSLog(@"error at signin111 %@",error); return; } else{ NSString *email = user.profile.email; NSString *name = user.profile.name; NSURL *imageURL; if ([GIDSignIn sharedInstance].currentUser.profile.hasImage){ NSUInteger dimension = round(120 * [[UIScreen mainScreen] scale]); imageURL = [user.profile imageURLWithDimension:dimension]; } NSLog(@"email %@ %@ %@",email,name,imageURL); [[GIDSignIn sharedInstance] signOut]; } } - (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController { [self presentViewController:viewController animated:YES completion:nil]; NSLog(@" login button clicked"); } - (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController { [self dismissViewControllerAnimated:YES completion:nil]; NSLog(@"dismiss sign in "); } - (void)reportAuthStatus { GIDGoogleUser *googleUser = [[GIDSignIn sharedInstance] currentUser]; if (googleUser.authentication) { NSLog(@"already login "); } else { // To authenticate, use Google+ sign-in button. NSLog(@" Not Login"); } } @end |
12: Now, at last, you have to change your own project info.plist file.
In the Project > Target > Info > URL Types panel, create a new item and paste yours REVERSED_CLIENT_ID
into the URL Schemes field. You can find yours REVERSED_CLIENT_ID
in the GoogleService-Info.plist
file.
13: Now Run.
14: You can also download sample apps go to https://github.com/googlesamples/google-services/tree/master/ios/signin/SignInExample .
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.