在 Realm 对象服务器上看不到数据库



我创建了一个方法来管理所有用户之间的共享表,但是我看不到这个表。我刚刚删除了"~"字符,如果我保留"~"字符,它可以工作,但表格只有所有者才能看到。我不知道为什么它不起作用。也许这不是在用户之间共享表的正确方法?

    static public func setGlobalDatabase(database:String,  completion: @escaping (_ realm: Realm?, _ error: Error?) -> Void) {
    let realmPath = RealmService.REALM_SERVER_DATA + "/" + ConstanteService.APP_DOMAINE + "-" + database
    let user = SyncUser.current
    if user == nil  {
        SyncUser.logIn(with: .usernamePassword(username: RealmService.username, password: RealmService.password, register: false), server: URL(string: RealmService.REALM_SERVER_HTTP)!) { user, error in
            guard let user = user else {
                completion(nil, error)
                return
            }
            DispatchQueue.main.async {

                // Open Realm
                let configuration = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: URL(string: realmPath)!))

               let permission = SyncPermissionValue(realmPath: realmPath,  // The remote Realm path on which to apply the changes
                    userID: "*", // The user ID for which these permission changes should be applied
                    accessLevel: .write)   // The access level to be granted
                user.applyPermission(permission) { error in
                    if let error = error {
                        // handle error
                        return
                    }
                    // permission was successfully applied
                }

                completion(try? Realm(configuration: configuration), nil)
            }
        }
    }
    else{
        DispatchQueue.main.async {
            // Open Realm
            let configuration = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user!, realmURL: URL(string: realmPath)!))
            completion(try? Realm(configuration: configuration), nil)
        }
    }
}

如果要将用户领域的权限授予其他用户(~/shared_user_realm(,则需要先检索其他用户设备上的权限,以获取shared_user_realm的完整路径并将其用于SyncConfiguration。在 https://realm.io/docs/swift/latest/#access-control 查看更多信息

如果你想拥有共享的全局领域(如/shared_realm(,你应该用管理员用户创建它(只有管理员有权访问/(并向其他用户授予权限。之后,您可以在应用程序中使用此领域。

相关内容

  • 没有找到相关文章

最新更新