我在这方面是新手,我正在寻找一个解决方案,以进入一个新的视图控制器登录后与谷歌。我想,登录是有效的,但是3天后我没有成功。我想在登录后进入其他空白的视窗控制器。我尝试了许多解决方案,可以在stackoverflow和google文档中找到,但似乎没有适用于我的Xcode版本的文档。
这是我的AppDelegate:
import UIKit
import Firebase
import GoogleSignIn
import FirebaseUI
@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.
FirebaseApp.configure()
GIDSignIn.sharedInstance()?.clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance()?.delegate = self
return true
}
// MARK: UISceneSession Lifecycle
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
if (error as NSError).code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue {
print("The user has not signed in before or they have since signed out.")
} else {
print("\(error.localizedDescription)")
}
return
}
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
print(fullName)
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { (authResult, error) in
if let error = error {
print("firebase sign in error")
print(error)
return
} else {
print("user is signed in with Firebase")
}
}
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any])
-> Bool {
return GIDSignIn.sharedInstance().handle(url)
}
}
}这是我的ViewController
import Firebase
import GoogleSignIn
import UIKit
import FirebaseAuth
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
GIDSignIn.sharedInstance()?.presentingViewController = self
GIDSignIn.sharedInstance()?.signIn()
GIDSignIn.sharedInstance()?.restorePreviousSignIn()
super.viewDidAppear(true)
let gSignIn = GIDSignInButton(frame: CGRect(x: 0,y: 0, width: 230, height: 48))
gSignIn.center = view.center
view.addSubview(gSignIn)
}
}如果有人能帮上忙,我将非常感谢。
发布于 2020-04-01 03:59:19
如下所示:
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
var vc: UIViewController?
vc = storyboard.instantiateViewController(withIdentifier: "signed")
window?.rootViewController = vc
window?.makeKeyAndVisible()https://stackoverflow.com/questions/60938241
复制相似问题