如何解决default.realm 数据到领域同步/云
我的应用是免费增值类型,用户可以免费使用该应用,但仅限离线使用,所有数据都存储在 default.realm
文件中。
一切正常,但当用户想要与其他设备同步时,他们需要订阅提供的订阅。
这给我带来了一个问题,当用户支付订阅费用时,应用程序将执行 sync.configuration
到 realm.Configuration
,但是一旦完成,应用程序中显示的所有数据在更改时都无法查看
问题:如何执行上传/请求realm云来同步default.realm中的所有数据?
*** 领域配置 ***
class RealmManager {
static let shared = RealmManager()
let realmApp = App(id: "xxxxxxxxxx")
lazy private var realmURL: URL = {
return Realm.Configuration.defaultConfiguration.fileURL!
}()
lazy private var config:Realm.Configuration = {
return Realm.Configuration(
fileURL: self.realmURL,inMemoryIdentifier: nil,syncConfiguration: nil,encryptionKey: nil,readOnly: false,schemaVersion: 1,migrationBlock: nil,deleteRealmIfMigrationNeeded: false,shouldCompactOnLaunch: { totalByte,usedByte in
let twentyMB = 20 * 1024 * 1024
return (totalByte > twentyMB) && (Double(usedByte) / Double(totalByte)) < 0.6
},objectTypes: nil
)}()
func realm(config:Realm.Configuration? = nil) -> Realm {
let user = realmApp.currentUser
var realm = try! Realm()
if ((user?.isLoggedIn) != nil) {
let partitionValue = user!.id
if realm.objects(usermodel.self).first != nil
&& realm.objects(usermodel.self).first?.typeID == UserType.Premium.rawValue {
print("online user with sync config")
realm = try! Realm(configuration: (user?.configuration(partitionValue: partitionValue))!)
} else {
print("online user without sync config")
realm = try! Realm(configuration: self.config)
}
}
else {
print("no sync config")
realm = try! Realm(configuration: self.config)
}
return realm
}
}
/// InAppPurchase: User completed transaction,perform sync to realm cloud
let user = RealmManager().realmApp.currentUser
let configuration = user?.configuration(partitionValue: user?.id ?? "")
_ = RealmManager().realm(config: configuration)
This is the error Code i received after perform /// InAppPurchase: User completed transaction,perform sync to realm cloud
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error:
Error Domain=io.realm Code=8 "Realm file is currently open in another process which cannot share access with this process.
All processes sharing a single file must be the same architecture.
For sharing files between the Realm browser and an iOS simulator,this means that you must use a 64-bit simulator.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。