There seems to be lack of info regarding the newest Xcode because all I have been seeing mentioned ViewController and AppDelegate files, which I do not have... Instead, I managed to make an AppDelegate class inside my app's main swift file (My project's name is Particeps, and thus the main file is ParticepsApp.swift)
However, I can't figure out how to go from the 'SignInview' to the 'MyCurrentLocationView' once the user is logged in. Below are my codes
ParticepsApp.swift
import SwiftUI
import Firebase
import GoogleSignIn
@main
struct ParticepsApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
SignInView(info: self.delegate)
}
}
}
class AppDelegate: NSObject,UIApplicationDelegate,GIDSignInDelegate,ObservableObject{
@Published var email = ""
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
FirebaseApp.configure()
GIDSignIn.sharedInstance()?.clientID =
FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
return true
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
guard let user = user else{
print(error.localizedDescription)
return}
let credential = GoogleAuthProvider.credential(withIDToken: user.authentication.idToken, accessToken: user.authentication.accessToken)
Auth.auth().signIn(with: credential) { (result, err) in
if err != nil{
print((err?.localizedDescription)!)
return
}
self.email = (result?.user.email)!
print(result?.user.email as Any)
}
}
}
SignInView.swift
import SwiftUI
import GoogleSignIn
struct SignInView: View {
@ObservedObject var info : AppDelegate
var body: some View {
VStack {
Button(action: {
GIDSignIn.sharedInstance()?.presentingViewController = UIApplication.shared.windows.first?.rootViewController
GIDSignIn.sharedInstance()?.signIn()
}) {
Text("Sign In")
.foregroundColor(.white)
.fontWeight(.bold)
.padding(.vertical,10)
.padding(.horizontal, 45)
.background(Color.red)
.clipShape(Capsule())
}
Text(info.email)
.padding(.top,25)
}
}
}
MyCurrentLocationView.swift
import SwiftUI
import MapKit
struct MyCurrentLocationView: View {
var body: some View {
Home()
}
}
struct Home: View {
.
.
.
}
Thanks a lot!