iOS: Google SignIn not working if delegate is not UIApplicationDelete
Ok, my bad. Of course after taking the time to post this I almost immediately found the problem.
Which had nothing to do with Google Sign In.
I'd accidentally set FirebaseSecurity
as a transient instance in my I container so it was being dealloc'd before the logon button was pressed. Doh!
I'll leave the question here even though everything is working. Perhaps someone else will learn something from my mistake. :-)
iOS Google Signin SDK webview not closing after signin
Make sure you are setting your UI delegate like so –
[GIDSignIn sharedInstance].uiDelegate = self;
You also need to implement –
- (void)signIn:(GIDSignIn *)signIn
dismissViewController:(UIViewController *)viewController
Inside that function you need to dismiss the Google view controller by calling [self dismissViewControllerAnimated:YES completion:nil];
Cannot find type GIDSignInDelegate in scope
As pointed out by Chris in the comments, follow the migration guide to update to GoogleSignIn 6.x.
See also this example of migrating the Firebase Auth QuickStart.
how to sign in with google in swiftui when there is no app delegate file inside the project?
This is for everyone having problem with AppDelegate SwiftUI 3.0 new update
Add in app view
import Foundation
import SwiftUI
import Firebase
import GoogleSignIn
@main
struct YourApp: App {
let persistenceController = PersistenceController.shared
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
return true
}
@available(iOS 9.0, *)
func application(_ application: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any])
-> Bool {
return GIDSignIn.sharedInstance.handle(url)
}
}
Then in loginView add inside login struct
@State var isLoading : Bool = false
func handleLogin(){
// google sign in
guard let clientID = FirebaseApp.app()?.options.clientID else { return }
// Create Google Sign In configuration object.
let config = GIDConfiguration(clientID: clientID)
isLoading = true
GIDSignIn.sharedInstance.signIn(with: config, presenting: getRootViewController()) { [self] user, error in
if let error = error {
isLoading = false
print(error.localizedDescription)
return
}
guard
let authentication = user?.authentication,
let idToken = authentication.idToken
else {
isLoading = false
return
}
let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: authentication.accessToken)
// Firebase Authentication
Auth.auth().signIn(with: credential) {result, err in
isLoading = false
if let error = error {
print(error.localizedDescription)
return
}
//Displaying User Name...
guard let user = result?.user else {
return
}
print(user.displayName ?? "Success" )
//updating user as logged in
withAnimation{
log_Status = true
// and this is where you want the user to go if successful
goHome()
}
}
}
}
where goHome() function is
public func goHome() {
if let window = UIApplication.shared.windows.first {
window.rootViewController = UIHostingController(rootView: HomeView())
window.makeKeyAndVisible()
}
}
also add this to loginView but as extension
extension View{
func getRect()->CGRect{
return UIScreen.main.bounds
}
// retrieve RootView
func getRootViewController()->UIViewController{
guard let screen = UIApplication.shared.connectedScenes.first as? UIWindowScene else {
return . init()
}
guard let root = screen.windows.first?.rootViewController else {
return .init()
}
return root
}
}
don't forget to give the button the handleLogin()
Button(action: {handleLogin()}) {
Image("Gmail")
}
.padding()
.foregroundColor(.white)
.background(Color.white)
.cornerRadius(.infinity)
and you are good to go my friends /p>
Related Topics
How to Use Sketch UI Elements Directly into Xcode
How to Use Pod in Notification Service Extension
iOS 7 Weather App Expand/Collapse Transition
Go Back to View Controller from Skscene
How to Make a Synchronous Request Using Alamofire
iOS 8 [Uiapplication Sharedapplication].Scheduledlocalnotifications Empty
How to Request Photo Gallery Permissions in iOS a Second Time
Contentview with UItableview Not Scrolling Within UIscrollview
Launching App from Sms Link or Email Link
Ld: Library Not Found for -Ldoubleconversion React Native 0.59
How to Override Convenience Init in Uialertcontroller for Swift
Check Whether Time Falls Between Two Time iOS
How to Make Inputaccessoryview Appear Above Uitabbarviewcontroller's Tabs
How to Detect If The HTML5 Autoplay Attribute Is Supported
Applying Different Attributes for Different Portions of an Nsattributedstring