【发布时间】:2017-05-02 22:44:37
【问题描述】:
我有一个本地 Realm 数据库,有 160000 行。我想将它复制到本地路径,以便 Realm 能够将其用作官方数据库,并在线同步。 (所以我的空数据库将被同步)。我可以这样做吗? (此时不起作用,因为它将 Db 复制到本地文件夹中,而不是在用户特定文件夹中)
func loginCompletedA(user: SyncUser) {
let realmURL = URL(string: “realm://xxx.compute-1.amazonaws.com:9080/beerUsers”)!
var configuration = Realm.Configuration.defaultConfiguration
configuration.syncConfiguration = SyncConfiguration(user: user, realmURL: realmURL)
let defaultURL = configuration.fileURL!
//let defaultParentURL = defaultURL.deletingLastPathComponent()
if let v0URL = Bundle.main.url(forResource: “default”, withExtension: “realm”){
do {
//if !ifNotExists {
try FileManager.default.removeItem(at: defaultURL)
//}
try FileManager.default.copyItem(at: v0URL, to: defaultURL)
} catch {}
do {
try FileManager.default.copyItem(at: v0URL, to: defaultURL)
} catch {}
}else{
}
let realm = try! Realm(configuration: configuration)
let session = user.session(for: realmURL)!
downloadToken = session.addProgressNotification(for: .download, mode: .reportIndefinitely) {
print(“download progress: \($0)“) // This is never called.
}
uploadToken = session.addProgressNotification(for: .upload, mode: .reportIndefinitely) {
print(“upload progress: \($0)“) // This is never called.
}
}
【问题讨论】:
标签: swift realm realm-mobile-platform