【发布时间】:2021-02-08 07:47:27
【问题描述】:
我正在尝试让我的应用程序使用 Google 功能登录,而不使用 Google 的预建按钮,而是使用 GIDSignIn.sharedInstance().signIn()。但是,它想先设置视图,但我不能,因为我使用没有 Storyboards 的 SwiftUI。
我在一个名为auth() 的类中定义了一个gLog() 函数,该函数存储为authC,然后我在视图中按下按钮时调用authC.gLog(),但是它存在线程问题并在此处响应此错误:Thread 1: "presentingViewController must be set."
查看文件(SwiftUI):
//
// ContentView.swift
// maraki-rev1
//
// Created by Max Webb on 25/10/20.
//
import SwiftUI
// base page name
var pageName: String = "Welcome"
var authC = auth()
struct ContentView: View {
var body: some View {
VStack{
Text(verbatim: data.userFirst)
.font(.title)
.multilineTextAlignment(.center)
Text("Please Log In Below")
.padding()
HStack{
Button(action: {
authC.gLog()
}) {
Text("Log In with Google")
.padding()
}
Button(action: {
authC.aLog()
}) {
Text("Log In with Apple")
.padding()
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
包含glog() 和auth() 类的类文件。
//
// authContent.swift
// maraki-rev1
//
// Created by Max Webb on 26/10/20.
//
import Foundation
import Firebase
import GoogleSignIn
import SwiftUI
class auth {
// google auth login
func gLog(){
GIDSignIn.sharedInstance().signIn()
}
func aLog(){
print("hello with apple")
}
}
网上没有其他东西可以提供帮助,而且他们缺乏围绕我的问题的教程,所以我感谢所有关于这个问题的答案和 cmet。
再次感谢马克斯。
【问题讨论】:
标签: swift firebase firebase-authentication swiftui google-signin