Hieu Vu
10/27/2025, 3:35 PM-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
*** 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 MaxHieu Vu
10/27/2025, 4:13 PMswiftPackageConfig {
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
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:
val googleSignInController = remember {
GoogleSignInController() // Use default init now
}
...
googleSignInController.signInCompletion { idToken, errorMessage, isCancelled ->
// Do stuff here
}