gpt4 book ai didi

ios - 在 SwiftUI 中调出 Google 登录屏幕

转载 作者:行者123 更新时间:2023-11-28 23:21:42 27 4
gpt4 key购买 nike

我正在使用 Google 登录屏幕和 swiftUI,但我的日志中不断收到一堆我不太理解的消息 - 现在我可以接受这些日志,但我遇到的问题是我不能多次调用同一个函数...

import SwiftUI
import GoogleSignIn

class GoogleStuff: UIViewController, GIDSignInDelegate, ObservableObject {

var googleSignIn = GIDSignIn.sharedInstance()
var googleId = ""
var googleIdToken = ""
var googleFirstName = ""
var googleLastName = ""
var googleEmail = ""
var googleProfileURL = ""

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {

guard user != nil else {
print("Uh oh. The user cancelled the Google login.")
return
}

print("TOKEN => \(user.authentication.idToken!)")


}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {

guard user != nil else {
print("Uh oh. The user cancelled the Google login.")
return
}

print("TOKEN => \(user.authentication.idToken!)")

}
}

struct ContentView: View {

let googleSignIn = GIDSignIn.sharedInstance()

@ObservedObject var myGoogle = GoogleStuff()

@State private var signedIn = false
@State private var buttonLabel = "Google Sign In"

var body: some View {
VStack {

Button(action: {
self.signedIn.toggle()
self.buttonLabel = self.signedIn ? "Google Sign In" : "Google Sign Out"

self.googleSignIn?.presentingViewController = UIApplication.shared.windows.last?.rootViewController
self.googleSignIn?.clientID = "MY_TOKEN_GOES_HERE" //It is just a playground for now
self.googleSignIn?.delegate = self.myGoogle
self.googleSignIn?.signIn()
}) {
HStack {
Image("GLogo")
.resizable()
.frame(width: 40, height: 40, alignment: .center)
Text(buttonLabel)
.foregroundColor(.blue)
.font(.title)
.font(.custom("Roboto-Thin", size: 20))
}
.padding()
.border(Color.black, width: 3)
}
}
}
}

我收到的错误信息是:

2020-01-03 10:25:14.490522+1300 gsignin[34333:10734362] [AXRuntimeCommon] This class 'SwiftUI.AccessibilityNode' is not a known serializable element and returning it as an accessibility element may lead to crashes

2020-01-03 10:25:14.789926+1300 gsignin[34333:10734511] [AXRuntimeCommon] Unknown client: gsignin

2020-01-03 10:25:16.539753+1300 gsignin[34333:10734362] Keyboard cannot present view controllers (attempted to present <SFAuthenticationViewController: 0x7f8a8a842200>)

问题 1: 我应该担心这个吗:[AXRuntimeCommon] Unknown client: gsignin

问题 2:收到此消息后,登录屏幕第一次出现,但此后任何时候都不会出现... Keyboard cannot present view controllers (attempted to present <SFAuthenticationViewController: 0x7f8a8a842200>)

如何修复这些消息?目前我一事无成。

附言。我不介意多做一些阅读/研究,但请保持友善 - 我是 swift 的新手:-D

最佳答案

改变自:

self.googleSignIn?.presentingViewController = 
UIApplication.shared.windows.last?.rootViewController

收件人:

self.googleSignIn?.presentingViewController = 
UIApplication.shared.windows.first?.rootViewController

成功了。

关于ios - 在 SwiftUI 中调出 Google 登录屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59570306/

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