Hi folks, I am implementing OAuth in iOS with Goog...
# multiplatform
h
Hi folks, I am implementing OAuth in iOS with GoogleSignIn and trigger it in CMP view. I face strange error when code runs through GoogleSignIn code. Do I miss something in the set up? I already add
-ObjC
flag, add dependencies from nativeBridge to XCode project (as per spmforkmp log says) So I used spmforkmp to get dependencies and implement it in Swift, then call it in Kotlin code. However, when the code run through GoogleSignInCode, it throws this error
Copy code
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[OIDAuthorizationService presentAuthorizationRequest:presentingViewController:callback:]: unrecognized selector sent to class 0x10d9370b0'
terminating due to uncaught exception of type NSException
CoreSimulator 1048 - Device: iPhone 15 Pro Max (4E2318C4-8258-4F78-A679-52CE4D6F3CE4) - Runtime: iOS 17.2 (21C62) - DeviceType: iPhone 15 Pro Max
Here's the code snippet This is my configuration for spmforkmp in build.gradle.kts
Copy code
swiftPackageConfig {
    create("nativeBridge") {
        dependency {
            linkerOpts = listOf("-ObjC", "-framework", "SystemConfiguration", "-framework", "Security")
            exportedPackageSettings {
                includeProduct = listOf("GoogleSignIn")
            }
            // Google Sign-In SDK
            remotePackageVersion(
                url = uri("<https://github.com/google/GoogleSignIn-iOS.git>"),
                products = {
                    add("GoogleSignIn")
                    add("GoogleSignInSwift") // Optional, for Swift UI support
                },
                version = "9.0.0",
            )
        }
    }
}
This is the Swift code
Copy code
import Foundation
import GoogleSignIn
import UIKit // Needed for UIViewController

// Define a public typealias for the completion handler closure
public typealias GoogleSignInCompletionHandler = (String?, String?, Bool) -> Void

@objcMembers public class GoogleSignInController: NSObject {

    public override init() {
        super.init()
    }

    public func signIn(completion: @escaping GoogleSignInCompletionHandler) {
        guard let presentingViewController = UIApplication.shared.keyWindow?.rootViewController else {
            completion(nil, "No root view controller found", false)
            return
        }

// Error throws from here
        GoogleSignIn.GIDSignIn.sharedInstance.signIn(withPresenting: presentingViewController) { signInResult, error in
           
        }
    }

    @objc public static func signOutGoogle() {
        GoogleSignIn.GIDSignIn.sharedInstance.signOut()
    }
}
Here is how I use it in Kotlin:
Copy code
val googleSignInController = remember {
        GoogleSignInController() // Use default init now
    }
...
googleSignInController.signInCompletion { idToken, errorMessage, isCancelled ->
    // Do stuff here
}