I tried to integrate Facebook/Google+ in my app. I can do that by the inbuilt Facebook framework, Google Plus framework, Google open source framework, in iOS app by getting the details from the account added in settings app of the device. I can also do it by opening the Safari browser and redirect to my app after login to Facebook and Goolge+. so, I need without redirect the Safari browser.
-
just remove the `URL Schema` in your .Plist – Anbu.Karthik May 15 '15 at 07:49
-
you can use UIWebView instead of redirecting to Safari. – Ritu May 15 '15 at 07:51
-
@Ritu -- your answer is the second option , if you are removed the `URL schema` in plist the Facebook provide the popup screen in inside the app – Anbu.Karthik May 15 '15 at 07:52
-
@Anbu.Karthik but it is not the case for google+. – Ritu May 15 '15 at 07:54
-
any sample app for UIWebView instead of redirect to safari? – Santhosh Kumar May 15 '15 at 08:20
4 Answers
Using new Google+ SDK, user will not have to reenter the password in safari or any browser. Take a look on this: https://developers.google.com/+/mobile/ios/sign-in
If the user has the native Google or Google+ mobile app installed then user will not have to re-enter their Google credentials to authorize your app.
OR
Try with GTMOAuth2ViewControllerTouch
- (id)initWithScope:(NSString *)scope
clientID:(NSString *)clientID
clientSecret:(NSString *)clientSecret
keychainItemName:(NSString *)keychainItemName
completionHandler:(GTMOAuth2ViewControllerCompletionHandler)handler
Plenty of references available online. Google Drive iOS SDK: Display Cancel Login Button
-
I think, you should check the google link: https://code.google.com/p/google-plus-platform/issues/detail?id=900 – Ritu May 15 '15 at 08:07
-
Thank you @Ritu for the link. Let me check directly with google developer. I'll update my answer based on his inputs. – Tariq May 15 '15 at 08:26
Don't use Google-Plus, use GoogleSignIn. Google just posted this solution:
Comment #109 on issue 900 by fa...@google.com: iOS SDK SignIn don't leave app [Apple appstore rejection] https://code.google.com/p/google-plus-platform/issues/detail?id=900
Hello everyone,
I’m delighted to announce an update to this issue. Today, we launched version 2.0 of Google Sign In, featuring full built-in support for Sign In via WebView. We hope that this update will at last remedy the problem of App Store rejections due to use of our SDK.
Full documentation is here: https://developers.google.com/identity/sign-in/ios
We’ve written a migration guide from G+ Sign In here: https://developers.google.com/identity/sign-in/ios/quick-migration-guide
- 12,116
- 8
- 48
- 74
You can use the below code to sign in via Google+ using Webview:
Initialize UIWebview:
NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%@&redirect_uri=%@&scope=%@",client_id,callbakc,scope];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[webView setDelegate:self];
[self.view addSubview:webView];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
Implementation of delegate methods:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
// [indicator startAnimating];
if ([[[request URL] host] isEqualToString:@"localhost"]) {
// Extract oauth_verifier from URL query
NSString* verifier = nil;
NSArray* urlParams = [[[request URL] query] componentsSeparatedByString:@"&"];
for (NSString* param in urlParams) {
NSArray* keyValue = [param componentsSeparatedByString:@"="];
NSString* key = [keyValue objectAtIndex:0];
if ([key isEqualToString:@"code"]) {
verifier = [keyValue objectAtIndex:1];
break;
}
}
if (verifier) {
NSString *authToken = [NSString stringWithFormat:@"code=%@&client_id=%@&client_secret=%@&redirect_uri=%@&grant_type=authorization_code", verifier,client_id,secret,callbakc];
//Use Token to Login
} else {
// ERROR!
}
[webView removeFromSuperview];
webView = nil;
return NO;
}
return YES;
}
- 661
- 3
- 8
-
This code will only return authToken not homeServerAuthorizationCode. Server code is required to enable server-side API access for the app. – Tariq May 18 '15 at 13:15
Use Scocial.framework https://developer.apple.com/library/ios/documentation/Social/Reference/Social_Framework/
__block ACAccount * facebookAccount;
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
NSDictionary *emailReadPermisson = @{
ACFacebookAppIdKey : @"YOUR_API_KEY",
ACFacebookPermissionsKey : @[@"email"],
ACFacebookAudienceKey : ACFacebookAudienceEveryone,
};
NSDictionary *publishWritePermisson = @{
ACFacebookAppIdKey : @"YOUR_API_KEY",
ACFacebookPermissionsKey : @[@"publish_actions"],
ACFacebookAudienceKey : ACFacebookAudienceEveryone
};
ACAccountType *facebookAccountType = [accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
//Request for Read permission
[accountStore requestAccessToAccountsWithType:facebookAccountType options:emailReadPermisson completion:^(BOOL granted, NSError *error) {if(granted){ // Enter your code}];
- 1