swift - 领域错误 Domain=io.realm.unknown Code=89 "操作取消"
问题描述
如果这是一个 URL 问题,我不知道。一切正常,但是在尝试异步打开领域时,出现域错误。
我的数据存储在数据库 Store.items 中。这是我的屏幕截图
我想将服务器数据同步到我的本地领域数据库。这是我的代码
我有一个 Constants.swift 文件
import Foundation
struct Constants {
// **** Realm Cloud Users:
// **** Replace MY_INSTANCE_ADDRESS with the hostname of your cloud instance
// **** e.g., "mycoolapp.us1.cloud.realm.io"
// ****
// ****
// **** ROS On-Premises Users
// **** Replace the AUTH_URL string with the fully qualified versions of
// **** address of your ROS server, e.g.: "http://127.0.0.1:9080"
static let MY_INSTANCE_ADDRESS = "app.us1a.cloud.realm.io" // <- update this
static let AUTH_URL = URL(string: "https://\(MY_INSTANCE_ADDRESS)")!
static let REALM_URL = URL(string: "realms://\(MY_INSTANCE_ADDRESS)/appName")!
}
override func viewDidLoad() {
super.viewDidLoad()
SyncServertoLocal()
}
@objc func SyncServertoLocal(){
print("trying to sync")
let config = SyncUser.current?.configuration(realmURL: Constants.REALM_URL, fullSynchronization: true)
Realm.asyncOpen(configuration: config!) { realm, error in
if let realm = realm {
// Realm successfully opened, with all remote data available
print("Remote data available")
} else if let error = error {
// Handle error that occurred while opening or downloading the contents of the Realm
print("Opps we have a realm problem", error)
}
}
}
哎呀,我们遇到了领域问题 Error Domain=io.realm.unknown Code=89 "Operation cancelled" UserInfo={Category=realm.basic_system, NSLocalizedDescription=Operation cancelled, Error Code=89}
似乎没有数据正在同步,但我不知道错误的含义以及如何修复它。如何修复错误?
解决方案
主要问题是您将现有的 Realm Sync 文档与BETA MongoDB Realm 文档混合在一起——这显然是一个常见问题。
两者之间的设置不同,您不能使用 MongoDB Realm 控制台访问您的 Realm Sync 数据库 - 它只能与BETA MongoDB Realm 一起使用。
这是MongoDB Realm Sync文档,指出您的对象需要具有与控制台上设置的分区键匹配的分区键。此外,连接顺序不同,看起来更像这样,包括分区和省略 fullSync(和其他)
let user = app.currentUser()
let partitionValue = "myPartition"
Realm.asyncOpen(configuration: user.configuration(partitionValue: partitionValue),
您问题中的代码适用于“经典”和当前的Realm Sync。如果您想坚持使用非测试版 Realm,您可以使用Realm Studio应用程序访问您的 Realm Sync 。
另请注意,使用对象也略有不同,因为您需要包含每个对象的分区值。例如,对于 MongoDB Realm,添加一个任务对象就是这个代码
try! realm.write {
realm.add(Task(partition: partitionValue, name: "My task"))
}
而对于经典的 Realm,它只是
try! realm.write {
realm.add(Task(name: "My task"))
}
推荐阅读
- html - 如何找到使用 XPath 找到的 HTML 元素的内容(Selenium with VBA)
- c - 在 C 中检查 NULL 的多个函数参数的有效方法
- javascript - 显示未定义的随机密码生成器
- c# - 二进制比较 .NET 程序集 - 忽略版本和时间戳
- c++ - C++。如何获得正确的输出?
- html - 如何在单选按钮之间添加空格?(HTML)
- swift - 你如何阻止视图阴影到达它一侧的另一个视图控制器?
- javascript - .then() 优先于 Promise 之外的代码?
- android - “/system/bin/sh: 语法错误:'(' 意外”在 ADB 中指定文件时
- reactjs - 如何在反应中添加选项到反应完美滚动条