Reputation: 31
I am trying to implement sign in with apple to Realm. I already did the configuration from the docs: https://www.mongodb.com/docs/atlas/app-services/authentication/apple/#std-label-apple-id-authentication
Now I am trying to add the sign in with Apple button and the flow.
The login button on SwiftUI:
SignInWithAppleButton(.signIn, onRequest: { request in
isLoggingIn = true
request.requestedScopes = [.email]
}, onCompletion: { result in
switch result {
case .success(let authResults):
guard let credentials = authResults.credential as? ASAuthorizationAppleIDCredential,
let identityToken = credentials.identityToken,
let identityTokenString = String(data: identityToken, encoding: .utf8) else { return }
repo.loginwithApple(appleTokenIDString: identityTokenString) { user, error in
}
case .failure(let error):
isLoggingIn = false
}
})
repo.loginwithApple
calls the method from the shared kotlin repository:
suspend fun loginwithApple(appleTokenIDString: String): User {
var credentials = Credentials.apple(idToken = appleTokenIDString)
return appService.login(credentials = credentials)
}
Whenever I try to do the login with the apple sign in button I get this exception:
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SharedRealmRepo loginwithAppleAppleTokenIDString:completionHandler:]: unrecognized selector sent to instance 0x281fe4960'
terminating with uncaught exception of type NSException
Any idea why the exception happens?
Upvotes: 0
Views: 141
Reputation:
It looks like removing the Output Files from XCode will solve the issue, but I do not know why.
Maybe someone has a explanation of why this happens. The output files will not let the realm repo re-build?
Upvotes: 0
Reputation: 5414
The error unrecognized selector sent to instance
means that the object repo
does not have that method, that is, loginwithApple
, with that signature, is not in your Kotlin code. This happens most probably because:
strings
from the command line.loginwithApple
to receive both a String and a closure, and this closure to take user, error. In your Kotlin code I don't see that closure, although my Kotlin is not good.public
I'd say is #2
Upvotes: 2