Leo*_*Leo 3 ios swift google-signin
我在Doc上做了任何事情,但是当我打电话时它崩溃了GIDSignIn.sharedInstance().signIn()。
在 AppDelegate:
func configGoogleServer() {
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError as Optional)")
GIDSignIn.sharedInstance().delegate = self
}
Run Code Online (Sandbox Code Playgroud)
在一些视图控制器:
GIDSignIn.sharedInstance().signIn()
Run Code Online (Sandbox Code Playgroud)
我已经配置了像com.googleusercontent.apps.598xxx...xxx.
调试区上没有任何显示...... :(
你把委托放在里面AppDelegate.swift,这不是真的,你的 AppDelegate 应该是这样的:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// .. something else
// GOOGLE
// Initialize sign-in
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
// No delegate here
return true
}
func application(_ application: UIApplication,
open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return GIDSignIn.sharedInstance().handle(url,
sourceApplication: sourceApplication,
annotation: annotation)
}
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String {
let annotation = options[UIApplicationOpenURLOptionsKey.annotation]
return GIDSignIn.sharedInstance().handle(url,
sourceApplication: sourceApplication,
annotation: annotation)
}
return true
}
Run Code Online (Sandbox Code Playgroud)
然后将 SignIn Delegate 放在 YourViewController 中,哪个登录操作会发生:?
class YourViewController: UIViewController {
// something else....
func doSignIn() {
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().scopes = YOUR_GOOGLE_SCOPES
if GIDSignIn.sharedInstance().hasAuthInKeychain() {
GIDSignIn.sharedInstance().signInSilently()
} else {
GIDSignIn.sharedInstance().signIn()
}
}
}
extension YourViewController: GIDSignInDelegate, GIDSignInUIDelegate {
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if let error = error {
self.showMessage("Authentication Error", type: .error)
self.service.authorizer = nil
} else {
self.service.authorizer = user.authentication.fetcherAuthorizer()
// PUT YOUR METHOD AFTER SIGNED-IN HERE
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1476 次 |
| 最近记录: |