This is my first question here after years of finding every answer I needed.
I have coded some apps for iPhone in IOS, I'm not always sure of what I'm doing but they work!
They use Google sign in and it's working fine. Now I want to code an app for Mac OS and the problem I can't get through is this line:
GIDSignIn.sharedInstance.signIn(withPresenting: rootViewController)
In this function:
func handleSignInButton() {
GIDSignIn.sharedInstance.signIn(
withPresenting: rootViewController) { signInResult, error in
guard let result = signInResult else {
// Inspect error
return
}
// If sign in succeeded, display the app's main content View.
}
)
}
In Google sign-in tutorial: https://developers.google.com/identity/sign-in/ios/sign-in
By what can I replace rootViewController in a Mac OS app?
I've tried something like this but I'm a bit lost :
GoogleSignInButton {
guard let presentingViewController = (NSApplication.shared.connectedScenes.first as? NSWindow)?.windows.first?.NSViewController else {return}
let signInConfig = GIDConfiguration.init(clientID: XXXXXXXXX")
GIDSignIn.sharedInstance.signIn(
with: signInConfig,
presentingWindow: presentingViewController) { user, error in
// check `error`; do something with `user`
}
}
Ss they advise on https://github.com/google/GoogleSignIn-iOS
Google Sign-In allows your users to sign in to your native macOS app using their Google account and default browser. When building for macOS, the signInWithConfiguration: and addScopes: methods take a presentingWindow: parameter in place of presentingViewController:. Note that in order for your macOS app to store credentials via the Keychain on macOS, you will need to sign your app.
Has someone used Google sign-in with SwiftUI for a Mac OS app?