问题
I don't if this is a URL issue. Everything works fine but when trying to Async open the realm, I get a domain error.
My data is stored in a database Store.items. Here is my screen shot
I want to sync to server data to my local realm database. here is my code
I have a Constants.swift file
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)
}
}
}
Opps we have a realm problem Error Domain=io.realm.unknown Code=89 "Operation canceled" UserInfo={Category=realm.basic_system, NSLocalizedDescription=Operation canceled, Error Code=89}
it appears like no data is syncing but I don't know what the error means and how to fix it. How can I fix the error?
回答1:
The main issue is that you're mixing the existing Realm Sync documentation with the BETA MongoDB Realm Documentation - apparently a common issue.
The setup is different between the two and you cannot use the MongoDB Realm console to access your Realm Sync database - it can only be used with the BETA MongoDB Realm.
Here's the MongoDB Realm Sync docs noting that your objects need to have a partition key that matches the one set up on the console. Additionally, the connection sequence is different and looks more like this, including the partition and omitting fullSync (and others)
let user = app.currentUser()
let partitionValue = "myPartition"
Realm.asyncOpen(configuration: user.configuration(partitionValue: partitionValue),
The code in your question is for the 'classic' and current Realm Sync. You can access your Realm Sync with the Realm Studio app if you want to stick with the non-beta Realm.
Also note that working with objects is slightly different as well because you need to include the partition value for each object. For example, with MongoDB Realm, adding a task object would be this code
try! realm.write {
realm.add(Task(partition: partitionValue, name: "My task"))
}
Whereas, with classic Realm its just
try! realm.write {
realm.add(Task(name: "My task"))
}
来源:https://stackoverflow.com/questions/62999928/realm-error-domain-io-realm-unknown-code-89-operation-canceled