I have enabled Realm Sync,
When I tried Realm Sync client Swift in Xcode 12 after adding realm sync framework and pod configuration, the following exception is blocking me to proceed in Future, Promise code.
The code where the problem is
app.login(credentials: Credentials.anonymous) {(result) in
// Remember to dispatch back to the main thread in completion handlers
// if you want to do anything on the UI.
DispatchQueue.main.async {
switch result {
case .failure(let error):
print("Login failed: \(error)")
case .success(let user):
print("Login as \(user) succeeded!")
// Continue below
self.OnLogin()
default:
self.OnLogin()
}
}
}
and the exception is
Contextual closure type ‘(RLMUser?, Error?) → Void’ expects 2 arguments, but 1 was used in closure body.
Thanks for the response and Solution,
I have made some changes in the Ream Database by mistake, Since then I could not open the Realm Object in the Client.
The Error message is “The Server has forgotten about this client to resume synchronization”
And the server side Error message is
client file not found { sessionIdent: 1, clientFileIdent: 4 } (ProtocolErrorCode=208)
Please help, Tried re create new project still does not help.
I have tried work around, like creating new Realm app in the Realm (Mongodb Atlas) and try to run the client.
Because of this I need to change the app id in the client.
But this time , the login is failed ( unanimous login ) and the error message is “Malformed JSON”
When I revert back the old app id it is logging in successfully.
You’ll probably need to go into the console, Terminate Sync and re-set it up. Ensure you select Developer Mode tab before doing so.
Also, you may need to completely delete all of the local files - that will cause it to re-sync the data from the server to the client (ensure you have a backup in case there’s local data you need).
I think you mean anonymous login. You need to ensure anonymous login is on. In console, go into any app then left column->Authentication then Authentication Providers tab and ensure it’s turned on. Don’t forget to review and deploy changes.
Second thing is there were recent changes to how users authenticate. See Anonymous Authentication - ensure your code matches let anonymousCredentials = Credentials.anonymous
Then as far as local files, if you’re doing iOS you need to reset the simulator. If your doing macOS you need to delete the files in user/library/Application Support/com.your_company.app_name. Again though, deleting those files will reset the client and cause all of the data on the server to re-sync so don’t do it unless you want local data erased.
Thanks a lot Jayson for the clear and detailed clarifications. It helped me lot to understand.
I find the anonymous authentication is enabled, and re sync,
But app.login for anonymous object comes out with nil RLMUser object and never return result, and I dont find and log showing in the server for login failure.
I could not able to make out for nil RLMUser object at client side.
Please help if it has been already encountered by some one resolved it.
That’s a little unclear. Based on your updated code that should look like this
your_app.login(credentials: creds) { result in
switch result {
case .failure(let error):
print(error.localizedDescription)
case .success(let user):
print("anon login success")
print(user.id) //just to show the id
}
}
does the code in the .failure case run or does the code in the .success run, put printing user.id prints nil?
Yes exactly, I am using the same code, it never goes to switch statement and skips it.
Means, it is not either success nor failure.
And I find in debug, that the RLMUser object is nil and therefore further I cannot use this user object to open the Realm.
@ALALASUNDARAM_SARAVA you mention ‘it never goes to switch statement and skips it’ Are you waiting for the result to complete? As this is an asynchronous call.