Can read only realms still only be opened using asyncOpen?


#1

Can read only realms still only be opened using asyncOpenWithConfiguration as described here https://github.com/realm/realm-cocoa/issues/4485 or has partials sync fixed this problem so that we can sync realms down without syncing anything back up?


#2

@nsnick Correct - partial sync fixes this


#3

The documentation for Realm Objective-C 3.5.0 still has the asyncOpen caveat for read only realms. I am still seeing a permission denied error when syncing a read only realm without asyncOpen. Is there something I should be doing to tell realm to use partial sync and not try to sync the whole realm other than setting isPartial in the syncConfiguration?


#4

@nsnick You should be setting isPartail sync to true yes. Is this a new realm? Can you check if the realm is listed as a full or reference realm in the RealmFile object of the /__admin realm please?


#5

This is on realm cloud. I only see /default and two user realms in realm studio; there is no /__admin realm. It is a new realm.

Also, RLMRealm.h says that subscribeToObjects:where:callback: is deprecated and that one should use -[RLMResults subscribe] but RLMResults.h doesn’t have any subscribe methods and the partial sync documentation here https://realm.io/docs/objc/latest/ doesn’t say that [RLMRealm subscribe] is deprecated. What is the current way to partially sync objects using objective-c?


#6

@nsnick You can do Show > show System Realms - and the /__admin Realm should appear.

So you are trying to synchronously open the default realm? How did you assign permissions? You can see the APIs here:
https://docs.realm.io/platform/using-synced-realms/access-control#realm-level

You will notice there is now a ModifySchema permission. Which is how we deal with opening a Realm that is read-only.

Subscribe is described here for Obj-C:
https://docs.realm.io/platform/using-synced-realms/syncing-data#subscribing-to-data

The code you are looking for is here:
https://realm.io/docs/objc/3.5.0/api/Classes/RLMResults.html#/c:objc(cs)RLMResults(im)subscribe

We are a bit behind on updating our docs.


#7

@ianward
The realm was listed as a full realm. I believe that is because I was having the user that created it treat it as a fully synced realm and all other users who are supposed to only have read only access to it treat it as a partially synced realm. I take it you can’t do that?

I am trying to sync one of the user created realms not the default realm.

For the subscribe method, is there a wildcard that will subscribe to all objects of a particular class?

Does a user need the ModifySchema permission in order to sync down a read only realm?

The API examples for setting object level permissions don’t work or are incomplete in Objective-C because there is no getUser() function in the Objective-C version of realm-cocoa. I am currently still using the old permission setting methods using RLMSyncPermission. Do I need to also use the new RLMPermissionRole or are object, class, and realm level permissions automatically set to allow all users if you don’t set any permissions?

When I try using the partial sync permission method below I get the error:
*** Terminating app due to uncaught exception ‘RLMException’, reason: ‘Object type ‘RLMPermissionRole’ is not managed by the Realm. If using a custom objectClasses / objectTypes array in your configuration, add RLMPermissionRole to the list of objectClasses / objectTypes.’

	RLMRealmConfiguration *realmConfig = [[RLMRealmConfiguration alloc] init];
    realmConfig.fileURL = [NSURL URLWithString:path];
    realmConfig.objectClasses = @[[Dog self], [Cat self]];
    RLMSyncConfiguration *syncConfig = [[RLMSyncConfiguration alloc] initWithUser:[RLMSyncUser currentUser] realmURL:remoteRealmURL];
    syncConfig.isPartial = TRUE;
    realmConfig.syncConfiguration = syncConfig;
    NSError *error = nil;
    RLMRealm *newRealm = [RLMRealm realmWithConfiguration:realmConfig error:&error];
    if (error != nil) {
	    callback(FALSE, error);
	    return;
    }

    [newRealm transactionWithBlock:^{
	    // Create the role
	    RLMPermissionRole *readWriteRole = [RLMPermissionRole createInRealm:newRealm withValue:@[@"read-write"]];

	    // Add the user to the role
	    RLMSyncUser *currentUser = [RLMSyncUser currentUser];
	    RLMPermissionUser *user = [RLMPermissionUser userInRealm:newRealm withIdentity:currentUser.identity];
	    [readOnlyRole.users addObject:user];

	    // Create a new permission object for the role and add it to the Realm permissions
	    RLMPermission *permission = [RLMPermission permissionForRoleNamed:readOnlyRole.name onRealm:newRealm];
	    permission.canRead = YES;
	    permission.canQuery = YES;
	    permission.canCreate = YES;
	    permission.canDelete = YES;
	    permission.canUpdate = YES;
	    permission.canModifySchema = YES;
	    permission.canSetPermissions = YES;
    }];

#8

@nsnick Can you please change the Realm from full to reference and then apply the Read permissions and then try to open the Realm? You can use Studio to rename the string for now


#9

@ianward
Yeah. I fixed the full to partial before encountering the problems in the above post. The problems in the above post are present when the realm is set to partial.


#10

The error message indicates that you need to include RLMPermissionRole where you define:
realmConfig.objectClasses =