从本地切换到同步的领域 [英] Switch from local to synced Realm

查看:80
本文介绍了从本地切换到同步的领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Realm Mobile Platform为我的应用程序提供同步,但不强制用户注册或登录.即,我想首先使用本地Realm,然后在切换到同步Realm时使用用户决定使用该功能.

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.

推荐答案

可以这样做,但是您不能自动将独立的Realm转换为同步的Realm(将来可能会更改).相反,您将创建另一个同步的Realm,然后将数据从独立Realm复制到其中.

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.

关于需要登录,当前要打开同步的Realm,您需要授权的User和同步的Realm URL.要获得授权的User,您必须使用各种凭据机制登录:当前支持用户名/密码,Google和Facebook.

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.

听起来像您需要的是一个匿名" User,其中Realm Object Server会在没有登录的情况下生成授权的User.我们计划在更高版本中添加此功能,并支持将凭据添加到User.这意味着您可以立即打开同步的Realm,而无需通过匿名" User登录,然后稍后要求最终用户登录,将实际凭据附加到User对象,这样,如果最终用户使用了另一台设备,他们可以使用相同的基础User对象登录并标识自己.

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.

这篇关于从本地切换到同步的领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆