`
贝壳水母
  • 浏览: 145776 次
  • 性别: Icon_minigender_1
  • 来自: 广州中低收入人群
社区版块
存档分类
最新评论

iOS GoogleSignIn接入

阅读更多
https://developers.google.com/identity/sign-in/ios/start-integrating
Google官方文档在这里,以下主要介绍不使用CocoaPods而进行手动配置需要留意的地方,以及怎么使用自定义的按钮

1.导入需要的资源和框架

下载玩SDK包后,会得到
·GoogleSignIn.framework
·GoogleSignIn.bundle
其中GoogleSignIn.bundle是google登录按钮的资源包,如果自己的应用里已经做了自定义的登录按钮,这个是用不到的,可以不加。

添加必须的依赖框架:
·AddressBook.framework
·StoreKit.framework
·SystemConfiguration.framework
还有一些框架没有列出来但可能会用到,比如遇到过一个报错

报错:
_CTFontManagerRegisterGraphicsFont Undefined symbols for architecture x86_64

解决:加CoreText.framework


2.项目配置

文档里提到的configuration file,在仅使用googleSignIn的时候不是必须的,而且后台下载对中文命名是拒绝的……(sad……)
所谓的GoogleService-Info.plist,其实作用只是在初始化的时候配置clientID,所以我们可以手动在自己target的Info.plist里加入一个,比如我就起名叫G_CLIENT_ID,甚至你在代码里hardcode都可以……



接着加URL Types,里面白纸黑字加截图,只填了Url Schemes的值


但其实Identifier也要填上的,这个可以在SDK附带的例子里可以看到


3.编码
参考这里:https://developers.google.com/identity/sign-in/ios/sign-in

文档中建议是把view controller也作为GIDSignInUIDelegate,这个是最简单的做法,但有时候我们自己关于googleSignIn,可能会有专门一个管理的类,mvc里叫controller吧,而且想把相关的代码都集中在这里,那么就需要曲折一点,实现:
signInWillDispatch:error:
signIn:presentViewController:
signIn:dismissViewController:
3个方法,
重点是 signIn:presentViewController: 和
signIn:dismissViewController:
举个例子,如果是cocos2d-x开发的话,可以在AppController里提供一个RootViewController的getter,然后在 signIn:presentViewController: 中,
RootViewController* ctrl = (RootViewController*)[AppController getRootViewCtrl];
[ctrl presentViewController:viewController animated:YES completion:nil];

signIn:dismissViewController:则是
RootViewController* ctrl = (RootViewController*)[AppController getRootViewCtrl];
[ctrl dismissViewControllerAnimated:YES completion:nil];


初始化,参考例子可以这样:
NSString *clientID = @"";
clientID = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"G_CLIENT_ID"];
NSLog(@"clientID = %@", clientID);
GIDSignIn* signIn = [GIDSignIn sharedInstance];
signIn.clientID = clientID;
signIn.shouldFetchBasicProfile = YES;
signIn.delegate = self;
signIn.uiDelegate = self;


登录的调用则最为简单,不需要导入GIDSignInButton什么的,在自己按钮的事件回调里直接:
[[GIDSignIn sharedInstance] signIn];

登出则是:
[[GIDSignIn sharedInstance] signOut];


以上是接入的关键以及文档可能没写好的地方,另外附上的是可能遇到的问题及解决方案

======================
报错:
-[__NSDictionaryM gtm_httpArgumentsString]: unrecognized selector sent to instance 0x1e887ea0'

解决:Other Linker Flags: -ObjC

======================
报错:
’When |allowsSignInWithWebView| is enabled, uiDelegate must either be a |UIViewController| or implement the |signIn:presentViewController:| and |signIn:dismissViewController:| methods from |GIDSignInUIDelegate|.

解决:implement GIDSignInUIDelegate

======================
报错:
LaunchServices: ERROR: There is no registered handler for URL scheme com-google-gidconsent-google
LaunchServices: ERROR: There is no registered handler for URL scheme com-google-gidconsent
LaunchServices: ERROR: There is no registered handler for URL scheme com.google.gppconsent.2.4.1
LaunchServices: ERROR: There is no registered handler for URL scheme com.google.gppconsent.2.4.0
解决:
无视,千万不要处理,如果把这几个加到了URL Type,会导致iOS9以下无法弹出web登录页面
  • 大小: 14 KB
  • 大小: 116.1 KB
  • 大小: 56 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics