[英]What is the correct iOS code for Google Sign-in
我最近将我的 GoogleSignin pod 从 3.x 更新到 4.1.1 以及从这里链接的文档:
https://developers.google.com/identity/sign-in/ios/sdk/
去这里:
https://developers.google.com/identity/sign-in/ios/sign-in
已经过时了。
#import <Google/SignIn.h>
他们有一些设置代码:
NSError* configureError; [[GGLContext sharedInstance] configureWithError: &configureError]; NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
这似乎已经过时了。
我找不到 4.1.x 特定的文档。
(我的意思是这个问题主要是为了让 Google Identity 更新文档。我知道答案,我将在下面发布)
Pod 文件的波纹管代码
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.2'
use_frameworks!
target ’App Target’ do
pod 'GoogleSignIn'
end
然后在 AppDelegate.swift 文件中添加 Header import GoogleSignIn然后func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { GIDSignIn.sharedInstance().clientID = "googlesigninclient id"; }
func application(_ app: UIApplication, open url: URL, options:
[UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url,
sourceApplication:
options[UIApplicationOpenURLOptionsKey.sourceApplication] as?
String,
annotation:
options[UIApplicationOpenURLOptionsKey.annotation])
}
现在在 ViewController 类中
class LoginViewController:UIViewController
,GIDSignInUIDelegate, GIDSignInDelegate {
//Add Button action for gmail login
@IBAction func loginWithGmail(_ sender: Any) {
GIDSignIn.sharedInstance().signIn()
}
//deleage method will call after gmail login
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if (error == nil) {//login success
} else {
//login fail
}
}
}
幸运的是,github 示例存储库得到维护。 根据这个承诺:
https://github.com/googlesamples/google-services/commit/39c243954be0e730963f79720265839f1c0b6deb
正确的导入是:
#import <GoogleSignIn/GoogleSignIn.h>
(如果需要,也可以使用@import GoogleSignIn
)
GGLContext
似乎已被删除,因此应该删除使用它的代码。 似乎没有其他等价物需要放置在它的位置。
通过这两项更改,Google 登录对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.