I’m having points implementing the google register course of in my swiftUI file. I consider i’ve imported the proper pods and have been at this for hours making an attempt to get this to work, however I preserve getting these comparable errors on line 142:
1: Can not convert worth of sort ‘GIDConfiguration’ to anticipated argument sort ‘UIViewController’
2: Can not discover ‘getRootViewController’ in scope
3: Additional trailing closure handed in name
4: Unable to deduce sort of a closure parameter ‘error’ within the present context
5: Unable to deduce sort of a closure parameter ‘person’ within the present context
I have been making an attempt to troubleshoot this in numerous alternative ways. Unsure what the issue is, pods, SDK, or one thing with my delegate. Thanks for the assistance. For some motive I do not see an Information.plist file on my left toolbar of this new venture. (Photograph connected beneath) I attempted to create one and goal it, however now none of my schemes are constructing :(( Any assist can be significantly appreciated on what goes incorrect right here!
Right here is my swiftUI code:
import SwiftUI
import Firebase
import AuthenticationServices
import UIKit
import GoogleSignIn
// Outline the CustomTextFieldStyle right here
struct CustomTextFieldStyle: TextFieldStyle {
var borderColor: Colour
func _body(configuration: TextField<Self._Label>) -> some View {
configuration
.padding(10)
.background(RoundedRectangle(cornerRadius: 8).fill(Colour.white))
.overlay(RoundedRectangle(cornerRadius: 8).stroke(borderColor, lineWidth: 1))
}
}
struct SignUp: View {
@State non-public var title: String = ""
@State non-public var electronic mail: String = ""
@State non-public var password: String = ""
@State non-public var confirmPassword: String = ""
non-public var isFormValid: Bool {
!title.isEmpty && !electronic mail.isEmpty && !password.isEmpty && !confirmPassword.isEmpty
}
non-public var confirmPasswordFieldColor: Colour {
if confirmPassword.isEmpty {
return Colour.grey
} else {
return password == confirmPassword ? Colour.inexperienced : Colour.pink
}
}
non-public var passwordFieldColor: Colour {
if !confirmPassword.isEmpty {
return password == confirmPassword ? Colour.inexperienced : Colour.grey
} else {
return Colour.grey
}
}
var physique: some View {
NavigationView {
VStack(spacing: 25) {
Spacer(minLength: 1)
TextField("Identify *", textual content: $title)
.textFieldStyle(CustomTextFieldStyle(borderColor: Colour.grey))
.padding(.horizontal)
TextField("E-mail *", textual content: $electronic mail)
.textFieldStyle(CustomTextFieldStyle(borderColor: Colour.grey))
.padding(.horizontal)
SecureField("Password *", textual content: $password)
.textFieldStyle(CustomTextFieldStyle(borderColor: passwordFieldColor))
.padding(.horizontal)
SecureField("Verify Password *", textual content: $confirmPassword)
.textFieldStyle(CustomTextFieldStyle(borderColor: confirmPasswordFieldColor))
.padding(.horizontal)
Button("Have already got an account? Log In", motion: switchToSignIn)
.padding(.backside, 10)
.font(.footnote)
.foregroundColor(.blue)
Button("Signal Up", motion: signUpTapped)
.disabled(!isFormValid || password != confirmPassword)
.body(width: 200, top: 50)
.background(isFormValid && password == confirmPassword ? Colour.blue : Colour.grey)
.foregroundColor(.white)
.font(.headline)
.cornerRadius(15)
.overlay(
RoundedRectangle(cornerRadius: 15)
.stroke(Colour.blue, lineWidth: 2)
)
.padding()
Button(motion: signInWithGoogle) {
HStack {
Picture("Google") // Substitute together with your picture title
.resizable()
.scaledToFit()
.body(width: 16, top: 16)
Textual content("Signal Up with Google")
}
.body(width: 280, top: 45)
.background(Colour.black)
.foregroundColor(.white)
.cornerRadius(10)
.padding()
}
SignInWithAppleButton(
onRequest: { request in
// Deal with Apple Signal Up request if wanted
},
onCompletion: { end in
// Deal with Apple Signal Up completion if wanted
}
)
.body(width: 280, top: 45)
.padding(3)
Spacer()
}
.padding()
.navigationTitle("Signal Up")
}
}
func signUpTapped() {
// Verify if the shape is legitimate and passwords match
guard isFormValid, password == confirmPassword else { return }
// Create a brand new person with Firebase Authentication
Auth.auth().createUser(withEmail: electronic mail, password: password) { authResult, error in
if let error = error {
// Deal with any errors right here, equivalent to displaying an alert
print("Error signing up: (error.localizedDescription)")
} else {
// The person is signed up efficiently
// Further steps after profitable signup, like navigating to a different view
print("Consumer signed up efficiently")
}
}
}
func switchToSignIn() {
// Logic to modify to the Signal In view
}
func signInWithGoogle() {
guard let clientID = FirebaseApp.app()?.choices.clientID else { return }
let config = GIDConfiguration(clientID: clientID)
GIDSignIn.sharedInstance.signIn(with: config, presenting: getRootViewController()) { [weak self] person, error in
if let error = error {
// Deal with error
print(error.localizedDescription)
return
}
guard
let authentication = person?.authentication,
let idToken = authentication.idToken
else {
return
}
let credential = GoogleAuthProvider.credential(withIDToken: idToken,
accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { authResult, error in
if let error = error {
// Deal with error
print(error.localizedDescription)
return
}
// Consumer is signed in
// You possibly can publish a notification or use a broadcast property to replace your UI
}
}
}
struct SignUpView_Previews: PreviewProvider {
static var previews: some View {
SignUp()
}
}
}