Xcode SwiftUI中的自定义Google登录按钮
我在使用SwiftUI制作自定义Google登录按钮时遇到问题。它将打开一个窗口,允许您登录,但当我尝试在文本字段中键入任何内容时,它不会键入任何内容。有人见过这个吗?这是我的应用程序代理(一些打印语句仅供我参考):Xcode SwiftUI中的自定义Google登录按钮,xcode,firebase,swiftui,google-signin,Xcode,Firebase,Swiftui,Google Signin,我在使用SwiftUI制作自定义Google登录按钮时遇到问题。它将打开一个窗口,允许您登录,但当我尝试在文本字段中键入任何内容时,它不会键入任何内容。有人见过这个吗?这是我的应用程序代理(一些打印语句仅供我参考): 我完全是个初学者,所以可能会犯一些愚蠢的错误。最好使用UIViewController(由UIViewRepresentable提供)登录社交网络,这样你就可以自定义按钮,而且SwiftUI view在GIDSignIn/facebookMaya中遇到一些问题-你试过使用Fireb
我完全是个初学者,所以可能会犯一些愚蠢的错误。最好使用UIViewController(由UIViewRepresentable提供)登录社交网络,这样你就可以自定义按钮,而且SwiftUI view在GIDSignIn/facebookMaya中遇到一些问题-你试过使用FirebaseUI吗?这可能是实现Firebase应用程序Google登录的最简单方法。有关如何在Swift应用程序中使用此功能的信息,请参阅和GitHub上的。而不是UIApplication.shared.windows.last?.rootViewController,请尝试UIApplication.shared.windows.first?.rootViewController更好地使用UIViewController(通过UIViewRepresentable)登录社交网络,因此,您可以自定义按钮,而且SwiftUI view在GIDSignIn/facebookMaya中遇到一些问题-您尝试过使用FirebaseUI吗?这可能是实现Firebase应用程序Google登录的最简单方法。有关如何在Swift应用程序中使用此选项的信息,请参阅和GitHub上的。而不是UIApplication.shared.windows.last?.rootViewController,请尝试UIApplication.shared.windows.first?.rootViewController
// AppDelegate.swift
// WasteLESS
//
// Created by Maya Reese on 5/26/20.
// Copyright © 2020 Maya Reese. All rights reserved.
//
import UIKit
import Firebase
import FBSDKCoreKit
import GoogleSignIn
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var user = UserData()
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
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
return true
}
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
ApplicationDelegate.shared.application(
application,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
return GIDSignIn.sharedInstance().handle(url)
}
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
if let error = error {
print(error.localizedDescription)
return
}
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { (res, err) in
if err != nil {
print((err?.localizedDescription)!)
return
}
self.user.authorized = true
}
}
}
func GoogleButtonTapped(){
GIDSignIn.sharedInstance().presentingViewController = UIApplication.shared.windows.last?.rootViewController
GIDSignIn.sharedInstance().signIn()
}