2017-05-13 5 views
0

すべてのユーザー間で共有テーブルを管理する方法を作成しましたが、このテーブルは表示されません。私はちょうど "〜"文字を削除していますが、それは "〜"文字を残しても動作しますが、テーブルにはオーナーしか見ることができません。私はなぜそれが動作しないのか分からない。おそらく、ユーザー間でテーブルを共有するのは適切な方法ではないでしょうか?レルムオブジェクトサーバーのデータベースが表示されません

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

    } 
} 

答えて

0

あなたが他のユーザー(~/shared_user_realm)へのユーザーのレルムの権限を付与したい場合は、shared_user_realmへの完全なパスを取得し、SyncConfigurationのためにそれを使用する最初の他のユーザーのデバイスにアクセス許可を取得する必要があります。あなたがグローバル領域(のような/shared_realm)を共有しているしたい場合は、あなたが他のユーザーにadminユーザー(管理者のみが/へのアクセス権を持っている)と、権限を与えて、それを作成する必要がありますhttps://realm.io/docs/swift/latest/#access-control

でより多くを参照してください。その後、あなたはあなたのアプリでこの領域を使うことができます。

関連する問題