问题
I would like to use the Realm Mobile Platform to provide syncing for my app, but not force the user to register or sign in. I.e., I would like to use a local Realm at first, then switch to a synced Realm if the user decides to use that feature.
Is this possible? I couldn't find anything regarding this in the documentation.
回答1:
This is possible to do, but you cannot automatically convert a standalone Realm into a synchronized Realm (in the future this could change). Instead, you would create a second synchronized Realm and then just copy the data from the standalone Realm into it.
As for requiring a login, currently to open a synchronized Realm you need an authorized User and the synced Realm URL. To get an authorized User, you must login with various credential mechanisms: username/password, Google, and Facebook are currently supported.
What it sounds like you need is an "anonymous" User, where Realm Object Server would generate an authorized User without a login. We plan to add this functionality in a later version and support for adding credentials to a User. This means that you could open a synchronized Realm immediately without a login via an "anonymous" User then later ask the end user to login, attaching actual credentials to the User object, such that if the end user used another device, they could login and identify themselves with the same underlying User object.
来源:https://stackoverflow.com/questions/39768828/switch-from-local-to-synced-realm