RealmBrowser-iOS icon indicating copy to clipboard operation
RealmBrowser-iOS copied to clipboard

Realm placed in an App Group won't show contents.

Open Sjoerdjanssenen opened this issue 8 years ago • 7 comments

My Realm is stored in an app group. When I load RLMBrowserViewController it will show me the correct models and the number of entries they have, but when I open a model it will show me an empty tableview.

When I place the Realm locally in the app, everything works fine.

Sjoerdjanssenen avatar Nov 21 '17 11:11 Sjoerdjanssenen

Ah, sorry @Sjoerdjanssenen! I haven't fully finished documenting it yet.

There's provisions for Realm files in app groups. But unfortunately there's no way to store the absolute file path URL to them (Because they dynamically change each time the app is launched), so they have to be manually registered before the Browser has enough information to generate the URL.

If you do this before you present the browser view controller, it SHOULD work.

[RLMBrowserViewController registerAppGroupRealmAtRelativePath:@"TodayWidget/TodayWidget.realm"
forGroupIdentifier:@"group.timoliver.icomics"];

Let me know how you go!

TimOliver avatar Nov 21 '17 11:11 TimOliver

Aah, thanks for the reply. So just to get this clear for me, this would mean I'd have to run that before initialising the RLMBrowserViewController?

[RLMBrowserViewController registerAppGroupRealmAtRelativePath:@"db.realm"
                                           forGroupIdentifier:@"group.myorganisation.myapp"];
RLMBrowserViewController *controller = [[RLMBrowserViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];

Sjoerdjanssenen avatar Nov 21 '17 19:11 Sjoerdjanssenen

Sorry for the delay!

Yep! As long as your Realm file is in the root directory of your app group, that SHOULD work as it is.

Let me know if it doesn’t. :)

TimOliver avatar Nov 26 '17 05:11 TimOliver

Thanks for the reply. It won't work for me with this code, though.

In my application, there's a Utilities class that contains the following methods:

+ (NSString *)getRealmPath {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.myorganisation.myapp"];
    NSString *path = [storeUrl path];
    path = [path stringByAppendingPathComponent:@"db.realm"];
    
    return path;
}

+ (RLMRealm *)getRealm {
    RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
    config.fileURL = [NSURL URLWithString:[self getRealmPath]];
    return [RLMRealm realmWithConfiguration:config error:nil];
}

And I present RLMBrowserViewController with the code I posted before:

[RLMBrowserViewController registerAppGroupRealmAtRelativePath:@"db.realm"
                                           forGroupIdentifier:@"group.myorganisation.myapp"];
RLMBrowserViewController *controller = [[RLMBrowserViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];

It won't show it's contents, though.

Sjoerdjanssenen avatar Nov 27 '17 20:11 Sjoerdjanssenen

Hmmm. Is it appearing in the Browser and you can tap on it at least?

TimOliver avatar Nov 28 '17 02:11 TimOliver

Yeah, I can see the Realm file and the models, but not the entries.

Sjoerdjanssenen avatar Nov 30 '17 12:11 Sjoerdjanssenen

If that's the case, it sounds like the Realm property metadata isn't getting captured properly. Hmm, I'm not sure how I can debug that. :(

TimOliver avatar Dec 01 '17 04:12 TimOliver