在Realm Object Server上看不到数据库 [英] Can't see the database on Realm Object Server
问题描述
我创建了一种方法来管理所有用户之间的共享表,但是我看不到该表.我刚刚删除了〜"字符,如果我保留了〜"字符,但该表仅对所有者可见,则可以使用.我不知道为什么它不起作用.也许这不是在用户之间共享表的正确方法?
I have created a method to manage shared table between all users however I can't see this table. I have just remove the "~" character, it works if I leave the "~" character but the table it's only visible by the owner. I don't know why it does not work. Maybe it's not the proper way to share a table between users?
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中查看更多-控制
If you want to grant permissions for user's realm to other users (~/shared_user_realm
) you need to retrieve permissions on other users' devices first to get the full path to shared_user_realm
and use it for SyncConfiguration
. See more at https://realm.io/docs/swift/latest/#access-control
如果要共享全局领域(例如/shared_realm
),则应使用管理员用户创建该领域(仅管理员有权访问/
)并将权限授予其他用户.之后,您可以在应用程序中使用此领域.
In case you want to have shared global realm (like /shared_realm
) you should create it with admin user (only admins have an access to /
) and grant permissions to other users. After that you can use this realm in your app.
这篇关于在Realm Object Server上看不到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!