我想将Google+登录功能集成到我的应用中。我使用过Google+ sdk,但它重定向到safari以登录到Google,我想在我的应用程序中打开该Web对话框。有人能帮助我解决这个问题吗?Google +在应用内登录
0
A
回答
1
我做到了。通过继承UIApplication类,然后在Web视图中处理URL。以下是代码:
将Google+ FrameWork添加到您的项目中。
现在,在身份验证调用中,通过嵌入UIAPPLICATION类来捕获该URL。
- (IBAction)btnGooglePlusTap:(id)sender
{
[[GPPSignIn sharedInstance] authenticate];
}
SubClassUIApplication.h
#import <UIKit/UIKit.h>
#define ApplicationOpenGoogleAuthNotification @"GoogleFriendInvitationPosted"
@interface SubClassUIApplication : UIApplication
@end
#import "SubClassUIApplication.h"
@implementation SubClassUIApplication
- (BOOL)openURL:(NSURL *)url
{
if([[url absoluteString] hasPrefix:@"googlechrome-x-callback:"])
{
return NO;//This will prevent call to Google Chrome App if installed.
}
else if([[url absoluteString] hasPrefix:@"https://accounts.google.com/o/oauth2/auth"])
{
[[NSNotificationCenter defaultCenter] postNotificationName:ApplicationOpenGoogleAuthNotification object:url];
return NO;// Here we will pass URL to notification and from notification observer , we will load web view.
}
else if ([[url absoluteString] hasPrefix:@"com.google"])
{
return NO;
}
return [super openURL:url];
}
@end
将此子类设置为info.plist文件中的主类。
现在打开URL发送到Web视图
- (void)catchNotificationforGooglePlusSharing:(NSNotification *)notiofication
{
NSURL *u=(NSURL *)notiofication.object;
UINavigationController *navWebView =(UINavigationController *) [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewNavController"];
WebViewController *vcWebView = navWebView.viewControllers[0];
vcWebView.webURL = u;
[self.navigationController presentViewController:navWebView animated:YES completion:Nil];
}
现在webviewcontroller.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *req= [[NSURLRequest alloc]initWithURL:webURL];
[webvGoogle loadRequest:req];
}
#pragma mark - UIWebViewDelegate method
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
BOOL canHandle = [GPPURLHandler handleURL:request.URL sourceApplication:@"com.apple.mobilesafari" annotation:nil];
if(canHandle == YES)
{
[self dismissViewControllerAnimated:YES completion:^
{
}];
}
return YES;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Error in loading : %@",error.description);
}
不要忘记注册您的类ApplicationOpenGoogleAuthNotification通知。
1
您可以使用Google Toolbox for Mac - OAuth 2 Controllers的GTMOAuth2ViewControllerTouch。
#import <GTMOAuth2ViewControllerTouch.h>
GTMOAuth2ViewControllerTouch *googleAuthViewController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:@"https://www.googleapis.com/auth/userinfo#email"
clientID:kClientId
clientSecret:kSecretId
keychainItemName:@"GooglePlus_Sample_App"
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[self.navigationController pushViewController:googleAuthViewController animated:YES];
这是在这里发现http://blog.krzyzanowskim.com/2015/02/22/google-sign-on-with-1password/样品,你可以找到完整的示例项目。
+0
我已经从webview处理了我自己的自我同样的概念,像这样...它的作品像魅力,也帮助我做出是否我想打开应用程序内的任何网址或在safari中。但是,谢谢你的回应。 – vivek 2015-02-25 05:34:53
相关问题
- 1. 网络应用Google登录
- 2. Google Play说要登录Google帐户(应用内结算)
- 3. 用Google登录使用Android登录
- 4. Concrete5用google登录
- 5. iCloud在应用程序内登录
- 6. Google+ API在登录时没有响应
- 7. Android应用内结算请登录Google帐户错误
- 8. Firebase Google登录
- 9. HtmlUnit Google登录
- 10. 登录时Google会被用Google+登录取代吗?
- 11. 将Google联合登录用于Google Apps和ASP.net应用程序
- 12. iOS可以在应用内登录社交帐户吗?
- 13. 用PHP登录到Google
- 14. Android Google+使用WebView登录
- 15. 使用Google帐户登录
- 16. Python使用urllib登录Google
- 17. MVC 4.0 - 使用Google登录
- 18. CodeIgniter使用google openid登录
- 19. Python Oauth2 - 用Google登录
- 20. Google+登录Winform使用C#
- 21. 如何使用Google登录?
- 22. 坚持使用Google登录在Firebase上登录?
- 23. 在不使用Google登录按钮的情况下登录到Google服务
- 24. 检查用户是否在Google+之前登录应用程序?
- 25. 在我的应用程序中使用Google +登录
- 26. 使用Google登录时在网络应用中切换帐户
- 27. Google登录JMeter,无法登录
- 28. Google单点登录?
- 29. Google登录失败
- 30. Android Google API登录
移除plist中的url方案 – 2014-10-09 05:32:11
@ Anbu.Karthik无法正常工作...它将重定向到goole +,但不会通过删除url方案返回到我们的应用程序 – vivek 2014-10-09 05:42:05
这不受SDK的支持。 – Steve 2014-10-09 06:40:39