我最近将我的 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
他们有一些设置代码:
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
}
}
}
关于ios - Google 登录的正确 iOS 代码是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47796040/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) | Powered by Discuz! X3.4 |