我想將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. DropBox應用內登錄
- 4. Android應用Facebook登錄記住用戶,但Google登錄不會
- 5. 使用Google帳戶登錄Grails應用程序登錄
- 6. 用Google登錄使用Android登錄
- 7. 使用Google+ API登錄Android應用
- 8. Concrete5用google登錄
- 9. 自定義Google應用登錄頁面
- 10. Google+ API在登錄時沒有響應
- 11. 內部錯誤的測試應用程序登錄到Google+
- 12. Android應用內結算請登錄Google帳戶錯誤
- 13. Google登錄API
- 14. Google +登錄
- 15. Firebase Google登錄
- 16. Google API登錄
- 17. Google+登錄Turbolinks
- 18. Google+ api登錄
- 19. HtmlUnit Google登錄
- 20. Quickblox Google登錄
- 21. 登錄時Google會被用Google+登錄取代嗎?
- 22. 將Google聯合登錄用於Google Apps和ASP.net應用程序
- 23. firebase v3 signInWithPopup google登錄內部錯誤
- 24. iOS可以在應用內登錄社交帳戶嗎?
- 25. 使用Google帳戶登錄
- 26. MVC 4.0 - 使用Google登錄
- 27. Google+登錄用戶出去
- 28. Google+登錄Winform使用C#
- 29. Google-plus使用AngularJs登錄
- 30. 如何使用Google登錄?
移除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