我正在使用一个同步的 Realm,为了安全起见,我需要一种只删除本地数据的方法。我不能使用 realm.deleteAll() 因为那会删除我同步到的 Realm 对象服务器中的所有内容,我只想删除本地数据。我还尝试使用 NSFilemanager.defaultManager().removeItemAtURL() 删除 Realm 文件,但根据 this所以发布这是无效的,因为 Realm 仍然会缓存自己。我需要一些方法来删除所有本地数据而不触及 ROS 上的任何内容,并要求它与 ROS 重新同步,然后才能再次检索任何内容。
最佳答案
您可以通过调用 SyncUser.logOut()
让用户从服务器注销。然后同步 session 等待所有本地更改上传到服务器,之后,本地 Realm 文件将被删除(可能会在下次应用启动时发生)。
Any pending local changes will continue to be uploaded until the Realm Object Server has been fully synchronized. Then, all of their local synced Realms will be deleted from their device on next app launch.
关于ios - 与 ROS 同步时仅删除本地 Realm ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45204855/