How to handle "sync is not enabled for this app"

Hello,

Is there any way to handle below error in Swift Realm:

" sync is not enabled for this app

Hello @Vishal_Deshai,

Hi Vishal,

My name is Josman and I am happy to assist you with this issue.

sync is not enabled for this app

Could you please explain a little bit more on the above? Usually, the above error will be thrown when you are attempting to use Realm Sync with a Realm App id that does not have Realm Sync enabled.

Looking forward to your response.

Kind Regards,
Josman

HI @Josman_Perez_Exposit

yes, you understood right. we have to handle this error from client side.

Is it possible?

Thanks in advance.

Hello @Vishal_Deshai ,

Unless I am missing something, there is anything you could potentially do to avoid this as this scenario seems odd from the Realm Sync POV. Are you trying to use Realm Sync collections in a non Realm Sync app? If so, for what purpose?

Looking forward to your response.

Regards,

Hi @Josman_Perez_Exposit

Thanks for the reply,

we have only requirement to show error message to the end user if we have terminated the sync.

If there is nay way to hanlde this error then it would be fine for us.

Thanks

Hello @Vishal_Deshai

we have only requirement to show error message to the end user if we have terminated the sync.
If there is nay way to hanlde this error then it would be fine for us.

Yes, if you want to react to Sync being terminated, you need to implement Client Reset on your client code. In other words, the client app must carry out a client reset on a given synced realm if the server is restored to a version older than the version on the client.

Here, you can find an example of a client reset handler implemented in Swift.

Be aware, that when you terminate and re-start Sync, your client will connect to the server with a lower version and this will trigger Client Reset on your device.

Please let me know if you have any additional questions or concerns regarding the details above.

Kind Regards,
Josman

Hi @Josman_Perez_Exposit

How Client Reset will trigger for first time login user??

As per our implementation, client reset will trigger once sync

Thanks

Hello @Vishal_Deshai

How Client Reset will trigger for first time login user??

Client Reset will only work when there is a local copy of the DB in the device. When a user opens the app for the first time, there is no local DB so a Client Reset will not be fired.

If you want to show a message for the user when Sync is not enabled, you could monitor the state or the connectionState of your current Realm Sync session.

However, I would like to mention that when Sync is back online, you need to perform your own custom Client Reset logic to avoid the loss of data. All the data that haven’t been synchronized since the last termination of Sync will be lost if there is no manual built-in mechanism in your callback for Client Reset in your code.

This manual procedure will consist of copying the data that have not been synchronized in the new backup realm created automatically by immediatelyHandleError to continue working without interruption for the user.

Please let me know if you have any additional questions or concerns regarding the details above.

Kind Regards,
Josman

Hi @Josman_Perez_Exposit ,

Thanks for the answer.

we are using async for the first time sync. so we will access realm instance after the sync.

Can you please tell me how can we access realm instance and its state before the sync??

Again thanks in advance.

Hello @Vishal_Deshai

I do not fully understand what you are trying to accomplish. Could you please explain to us the complete use case you are trying to follow?

Can you please tell me how can we access realm instance and its state before the sync??

You cannot access the instance before Sync, since you need to authenticate first to be able to access your Sync session. When using async to open a Realm with Sync disabled this will throw the message: Connection[1]: Received: ERROR \"sync is not enabled for this app

Currently, there is no automatic way to intercept this message, therefore you would need to create your own syncManager.logger method for intercepting it.

app.syncManager.logger = { level, message in
    ...
}

However, I would want to point out that in a production application it’s a fairly critical mistake to be trying to use sync without it being turned on for your application. I would sincerely hope this wouldn’t happen in production.

Please let me know if you have any additional questions or concerns regarding the details above.

Kind Regards,
Josman

I don’t mean to hijack this question but I am facing a similar scenario where I would like to handle this error. In the case where the sync has been temporarily paused for maintenance or the sync has been terminated and is in the process of being reset (which may only be for a couple of minutes), and a new user is potentially attempting to create/access/sync a new realm, how should the “sync is not enabled” error be best handled?