Gmail integration in ios app

I am working on ios Application, recently I have a new requirement for it to provide the user with the ability to log in using gmail. when the user clicked on the login button, I want to open the Gmail login screen and after the user enters his credentials, if the credentials are correct and not open his mail, I want the control to go to the home page of my application. can someone tell me how to achieve this

+4
source share
2 answers

Finally, I found a solution ... I think it will help someone else Follow the instructions below to integrate gmail with your application.

1. Add the following classes to the project.

GTMHTTPFetcher.h, GTMHTTPFetcher.m, GTMOAuth2Authentication.h, GTMOAuth2Authentication.m, GTMOAuth2SignIn.h, GTMOAuth2SignIn.m, GTMOAuth2ViewControllerTouch.h, GTMOAuth2ViewControlMJTh.m.bh.m.

you will get the following classes: https://github.com/jonmountjoy/Force.com-iOS-oAuth-2.0-Example

Note If you are working in an ARC environment, you need to disable ARC for the following files:
GTMHTTPFetcher.m, GTMOAuth2Authentication.m, GTMOAuth2SignIn.m, GTMOAuth2ViewControllerTouch.m

To disable ARC for source files in Xcode 4, select the project and target in Xcode. Under the Phase Build tab, expand the compile source assembly phase, select the library source files, then press Enter to open the edit box and enter fno-objc-arc as the compiler flag for these files.

2. add the following frames

security.framework , systemConfiguration.framework 

3. Register your application in the google api console .... here: https://code.google.com/apis/console

Then go to the ApiAccess section, create a client identifier for the iOS application. then you will get clientID, ClientSecret and RedirectUrl

* 4. Now it is time for coding.,. *
create a signIn button in the controller and set the action for this. Here, when the user clicks the button, the calling method SignInGoogleButtonClicked is called.

 //import GTMOAuth2Authentication , GTMOAuth2ViewControllerTouch #define GoogleClientID @"paster your client id" #define GoogleClientSecret @"paste your client secret" #define GoogleAuthURL @"https://accounts.google.com/o/oauth2/auth" #define GoogleTokenURL @"https://accounts.google.com/o/oauth2/token" -(void) SignInGoogleButtonClicked { NSURL * tokenURL = [NSURL URLWithString:GoogleTokenURL]; NSString * redirectURI = @"urn:ietf:wg:oauth:2.0:oob"; GTMOAuth2Authentication * auth; auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"google" tokenURL:tokenURL redirectURI:redirectURI clientID:GoogleClientID clientSecret:GoogleClientSecret]; auth.scope = @"https://www.googleapis.com/auth/plus.me"; GTMOAuth2ViewControllerTouch * viewcontroller = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth authorizationURL:[NSURL URLWithString:GoogleAuthURL] keychainItemName:@"GoogleKeychainName" delegate:self finishedSelector:@selector(viewController:finishedWithAuth:error:)]; [self.navigationController pushViewController:viewcontroller animated:YES]; } //this method is called when authentication finished - (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController finishedWithAuth:(GTMOAuth2Authentication * )auth error:(NSError * )error { if (error != nil) { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error Authorizing with Google" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } else { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert !" message:@"success" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } } 
+2
source

I found him. but then I can just get a fragment, that is, the first few words of the body of the email, and not just everything. I just stopped, I did not find another way to do this. because I am using OAuth 2.0.

0
source

Source: https://habr.com/ru/post/978069/


All Articles