我一直在尝试在我一直在构建的新应用程序中实现苹果的登录和谷歌登录。但是我一直收到这个错误。有人能帮我一下吗?
这是我的Login.swift文件的代码。
import SwiftUI
import AuthenticationServices
import GoogleSignIn
import GoogleSignInSwift
import Firebase
struct Login: View {
// @StateObject var loginModel: LoginViewModel = .init()
@StateObject var loginModel = LoginViewModel()
var body: some View {
ScrollView(.vertical, showsIndicators: false){
VStack(alignment: .leading, spacing: 5){
Image(systemName: "person")
//.clipShape(.Circle)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 75, height: 75)
//.font(.system(size: 40))
.foregroundColor(.black)
.ignoresSafeArea()
(Text("Welcome")
.foregroundColor(.black) +
Text("n Login to Continue")
.foregroundColor(.secondary)
)
.font(.title)
.fontWeight(.semibold)
.lineSpacing(10)
.padding(.top, 20)
.padding(.trailing, 15)
//Mark Custom Text Field
CustomTextField(hint: "+16505551234", text: $loginModel.mobileNo)
.disabled(loginModel.showOTPField)
.opacity(loginModel.showOTPField ? 0.4 : 1)
.overlay(alignment: .trailing, content:{
Button("Change"){
withAnimation(.easeInOut){
loginModel.showOTPField = false
loginModel.otpCode = ""
loginModel.CLIENT_CODE = ""
}
}
.font(.caption)
.foregroundColor(.indigo)
.opacity(loginModel.showOTPField ? 1 : 0)
.padding(.trailing, 15)
})
.padding(.top, 40)
CustomTextField(hint: "OTP Code", text: $loginModel.otpCode)
.disabled(!loginModel.showOTPField)
.opacity(!loginModel.showOTPField ? 0.4 : 1)
.padding(.top, 20)
Button(action: loginModel.showOTPField ? loginModel.VerifyOTPCode: loginModel.getOTPCode) {
HStack(spacing: 15){
Text(loginModel.showOTPField ? "Verify Code" : "Get OTP")
.fontWeight(.semibold)
.contentTransition(.identity)
Image(systemName: "line.diagonal.arrow")
.font(.title3)
.rotationEffect(.init(degrees: 45))
}
.foregroundColor(.black)
.padding(.horizontal, 25)
.padding(.vertical)
.background{
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(.black.opacity(0.05))
}
.padding(.top, 10)
}
Text("(OR)")
.foregroundColor(.gray)
.frame(maxWidth: .infinity)
.padding(.top,10)
.padding(.bottom, 20)
.padding(.leading, -60)
.padding(.horizontal)
HStack (spacing: 8){
//Mark Space for Apple Sign in
CustomButton()
.overlay{
//Apple Sign in Button
SignInWithAppleButton{ (request) in
//requesting parameter from apple login
loginModel.nonce = randomNonceString()
request.requestedScopes = [.email,.fullName]
request.nonce = sha256(loginModel.nonce)
} onCompletion: { (result) in
switch result{
case .success(let user):
print("Success")
guard let credential = user.credential as? ASAuthorizationAppleIDCredential else{
print("Error with Firebase")
return
}
loginModel.appleAuthenticate(credential: credential)
case .failure(let error):
print(error.localizedDescription)
}
}
.signInWithAppleButtonStyle(.white)
.frame(height: 55)
.blendMode(.overlay)
}
.clipped()
//Mark: Custom Google Sign in Button
//comment from here
CustomButton(isGoogle: true)
.overlay{
if let clientID = FirebaseApp.app()?.options.clientID{
GoogleSignInButton{
GIDSignIn.sharedInstance.signIn(with: .init(clientID: clientID ), presenting: UIApplication.shared.rootController()){
user,error in
if let error = error {
print(error.localizedDescription)
return
}
//Login Google user to firebase
if let user
{
loginModel.logGoogleUser(user: user)
}
}
}
.blendMode(.overlay)
}
}
.clipped()
//comment ends here
}
.padding(.leading, -60)
.frame(maxWidth: .infinity)
}
.padding(.leading,60)
.padding(.vertical,15)
// .blendMode(.overlay)
}
.alert(loginModel.errorMessage, isPresented: $loginModel.showError){
}
}
@ViewBuilder
func CustomButton(isGoogle: Bool = false)-> some View{
HStack{
Group{
if isGoogle{
Image("Google")
.resizable()
.renderingMode(.template)
}else{
Image(systemName: "applelogo")
.resizable()
}
}
.aspectRatio(contentMode: .fit)
.frame(width: 25, height: 25)
.frame(height: 45)
Text("(isGoogle ? "Google" : "Apple") Sign In")
.font(.callout)
.lineLimit(1)
}
.foregroundColor(.white)
.padding(.horizontal,15)
.background{
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(.black)
}
}
}
struct Login_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
我想在HSTACK中放置一个相邻的苹果登录和谷歌登录。
如果你想看整个代码,请告诉我,因为它已经上传到Git中,但目前是私有的。
我通过将google sign in包降级到6.2.4版本来解决这个问题。但最终出现了我正在解决的问题。要降级,首先删除包(谷歌如何删除swift包,已经有大量的文档,所以不打算解释),一旦完成,请按照add package搜索明确的包版本并安装以解决相同的问题。