【问题标题】:Realm Error Domain=io.realm.unknown Code=89 "Operation canceled"领域错误 Domain=io.realm.unknown Code=89 "操作取消"
【发布时间】:2020-07-20 16:35:12
【问题描述】:

如果这是一个 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)
                            
                         }
                     }
              
    }

Opps 我们遇到领域问题 Error Domain=io.realm.unknown Code=89 "Operation cancelled" UserInfo={Category=realm.basic_system, NSLocalizedDescription=Operation cancelled, Error Code=89}

似乎没有数据正在同步,但我不知道错误的含义以及如何修复它。我该如何解决这个错误?

【问题讨论】:

    标签: swift realm


    【解决方案1】:

    主要问题是您将现有的 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"))
    }
    

    【讨论】:

    • 谢谢。 Realm 文档非常混乱,而且很多时候已经过时了。
    • @Jay 我遇到了完全相同的问题,但配置不同,我在这里提出了一个问题:stackoverflow.com/questions/63014699/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多