无法在Realm Object Server上看到数据库

时间:2017-05-13 08:35:35

标签: realm realm-mobile-platform realm-object-server

我已经创建了一种方法来管理所有用户之间的共享表,但我无法看到此表。我刚刚删除了"〜"性格,如果我离开"〜"字符,但表只有所有者可见。我不知道为什么它不起作用。也许它不是在用户之间共享表格的正确方法?

    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)
        }

    }
}

1 个答案:

答案 0 :(得分:1)

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

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.