8 Feb 2017

Google Sign in Integration into iOS App with Clear Steps n Images…


Google Sign in Integration into iOS App with Clear Steps n Images…


Google Sign in Integration into iOS App Clear Steps…


  1. Create A new Project with name GoogleSignInApp (Existed or Create depends on…) and close the project.
  2. Open terminal with (Command + Space) and type Terminal
  3. Terminal opened First Install Cocoa  pods using Command $ sudo gem install cocoapods ( if already installed no need…)
  4. Then in Terminal Go to your project Directory by using the Command   cd

Screen Shot 2017-02-08 at 12.01.35 PM.png

5.Then in terminal pod init
6.open podfile

Screen Shot 2017-02-08 at 12.03.52 PM.png
7. pod file created in project and a new window opened with the title pod file as shown below.
Screen Shot 2017-02-08 at 12.04.48 PM.png
8.Add pod 'Google/SignIn' as shown below(note: use (Ctrl + “) to get straight quote like this   ’  )
Screen Shot 2017-02-08 at 12.10.34 PM.png9. Then Save pod file by using (command + S) and close pod file using (command +W)
10. Now in already opened Terminal   pod install  as shown below.. pods installed successfully in our project…
Screen Shot 2017-02-08 at 12.15.06 PM.png
11. Close terminal (command  + W)
12. Now open Project and Check pods folder to see added pods or not..?
13. Open Workspace created in our project
14. once see this Link…
15. Then Click on GET A CONFIGURATION FILE or Click below Link..
Screen Shot 2017-02-08 at 12.25.04 PM.png
16. Give App name (Its not necessary to give your app name…)
17. iOS Bundle ID (Which is available in our project)
18. Your country
19. Then CONTINUE TO Choose  and configure services
20. Enable Google sign-In as shown below…
Screen Shot 2017-02-08 at 12.31.20 PM.png
21. Then CONTINUE TO Generate configuration files
Screen Shot 2017-02-08 at 12.35.46 PM.png
Screen Shot 2017-02-08 at 12.36.14 PM.png
22. Download GoogleService-Info.plist (which downloaded into downloads)
23. Then Click Continue Adding Sign-In
24. Drag the GoogleService-Info.plist file you just downloaded into the root of your Xcode project
Screen Shot 2017-02-08 at 12.41.34 PM.png
26. In the Project > Target > Info > URL Types panel, create a new item and paste your REVERSED_CLIENT_ID into the URL Schemes field. You can find your REVERSED_CLIENT_ID in the GoogleService-Info.plist file.
27. Also in the Project > Target > Info > URL Types panel, create a new item and type your bundle identifier in the URL Schemes field.
28. In your app delegate's .h file, declare that this class implements the GIDSignInDelegate protocol.

#import <Google/SignIn.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, GIDSignInDelegate>

29. In your app delegate's application:didFinishLaunchingWithOptions: method, configure the GGLContext shared instance and set the sign-in delegate.

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  NSError* configureError;
  [[GGLContext sharedInstance] configureWithError: &configureError];
  NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

  [GIDSignIn sharedInstance].delegate = self;

  return YES;
}

30. Implement the application:openURL:options: method of your app delegate. The method should call the handleURL method of the GIDSignIn instance, which will properly handle the URL that your application receives at the end of the authentication process.
- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary *)options {
  return [[GIDSignIn sharedInstance] handleURL:url
                             sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                    annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}

For your app to run on iOS 8 and older, also implement the deprecated application:openURL:sourceApplication:annotation: method.

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
  return [[GIDSignIn sharedInstance] handleURL:url
                             sourceApplication:sourceApplication
                                    annotation:annotation];
}

31.In the app delegate, implement the GIDSignInDelegate protocol to handle the sign-in process by defining the following methods:

*** This Code is to get user Details from Google with Google Sign in****

- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
     withError:(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 server
  NSString *fullName = user.profile.name;
  NSString *givenName = user.profile.givenName;
  NSString *familyName = user.profile.familyName;
  NSString *email = user.profile.email;
  // ...
}

- (void)signIn:(GIDSignIn *)signIn
didDisconnectWithUser:(GIDGoogleUser *)user
     withError:(NSError *)error {
  // Perform any operations when the user disconnects from app here.
  // ...
}


32. Next, you will add the Google Sign-In button so that the user can initiate the sign-in process. Make the following changes to the view controller that manages your app's sign-in screen:                                                                                                                         In the view controller's .h file, add the Google Sign-In interface and declare that this class implements the GIDSignInUIDelegate protocol.

#import <Google/SignIn.h>


@interface ViewController : UIViewController <GIDSignInUIDelegate>

  1. Add a GIDSignInButton to your storyboard, XIB file, or instantiate it programmatically. To add the button to your storyboard or XIB file, add a View and set its custom class to GIDSignInButton.
If you want to customize the button, do the following:
  • In your view controller's .h file, declare the sign-in button as a property.
    @property(weak, nonatomic) IBOutlet GIDSignInButton *signInButton;
  • Connect the button to the signInButton property you just declared.
  • Customize the button by setting the properties of the GIDSignInButton object.

**** in IBOutlet Write below Code****

  [[GIDSignIn sharedInstance] signIn];


33. You can use the signOut method of the GIDSignIn object to sign out your user on the current device, for example:

- (IBAction)didTapSignOut:(id)sender {
  [[GIDSignIn sharedInstance] signOut];
}


No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0