gpt4 book ai didi

ios - 操作无法完成

转载 作者:行者123 更新时间:2023-11-28 13:55:06 27 4
gpt4 key购买 nike

我正在将 google 登录集成到我的 Swift 项目中,它出现了一些错误。

Error: The operation couldn’t be completed. (com.google.GIDSignIn error -4.)

我点击了这个链接:https://developers.google.com/identity/sign-in/ios/start-integrating?refresh=1

我的代码是:在AppDelegate.swift

import UIKit
import GoogleSignIn

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

// Initialize sign-in
GIDSignIn.sharedInstance().clientID = "15084783084-s3siolgukj7ikgqhfgcvo2e7i4jb9.apps.googleusercontent.com"
GIDSignIn.sharedInstance().delegate = self

return true
}

private func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL?,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation])
}

private func application(application: UIApplication,
openURL url: URL, sourceApplication: String?, annotation: Any?) -> Bool {
var _: [String: AnyObject] = [UIApplication.OpenURLOptionsKey.sourceApplication.rawValue: sourceApplication as AnyObject,
UIApplication.OpenURLOptionsKey.annotation.rawValue: annotation as AnyObject]
return GIDSignIn.sharedInstance().handle(url,
sourceApplication: sourceApplication,
annotation: annotation)
}

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if let error = error {
print("\(error.localizedDescription)")
} else {
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
// ...
}
}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
}

ViewController.swift

import UIKit
import GoogleSignIn

class ViewController: UIViewController, GIDSignInUIDelegate {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

GIDSignIn.sharedInstance().uiDelegate = self

}

@IBAction func onClickGoogleSignIn(_ sender: UIButton) {

GIDSignIn.sharedInstance().signInSilently()

// GIDSignIn.sharedInstance().signOut()

}

}

我的要求是点击登录按钮时我想登录

最佳答案

SignIn方法中,

使用这段代码:

@IBAction func onClickGoogleSignIn(_ sender: UIButton) {
GIDSignIn.sharedInstance().signOut() //if already signed in, then sign out and have fresh sign in again
GIDSignIn.sharedInstance().signIn()
}

代替

GIDSignIn.sharedInstance().signInSilently()

关于ios - 操作无法完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53985490/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com