https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
u

लातों वाला भूत

10/10/2023, 12:30 AM
Hi Everyone. Has anyone been able to integrate Google Sign for iOS for Compose Multiplatform? For Android I have got it working but with iOS. I am unable to figure out the presenting view controller. Here is my code
Copy code
if (GIDSignIn.sharedInstance.hasPreviousSignIn()) {
                GIDSignIn.sharedInstance.restorePreviousSignInWithCompletion { user, error ->
                    if (error != null) onError(Throwable(error.localizedFailureReason))
                    else user?.idToken?.tokenString?.let(onIdToken)
                }
            } else {
                val config = GIDConfiguration(clientID = BuildKonfig.GOOGLE_WEB_CLIENT_ID)
                val windowScene =
                    UIApplication.sharedApplication.connectedScenes.first() as? UIWindowScene
                        ?: throw Throwable("No Window Scene Found")

                val keyWindow = (UIApplication.sharedApplication.connectedScenes.first {
                    (it as UIWindowScene).activationState == UISceneActivationStateForegroundActive
                } as? UIWindowScene)?.keyWindow ?: throw Throwable("No Window Scene Found")

                val rootViewController =
                    keyWindow.rootViewController ?: throw Throwable(
                        "No Root View Controller Found"
                    )

                GIDSignIn.sharedInstance
                    .signInWithPresentingViewController(rootViewController) { result, error ->
                        if (error != null) onError(Throwable(error.localizedFailureReason))
                        else result?.user?.idToken?.tokenString.let(onIdToken)
                    }
            }