dracula
dracula

Reputation: 4473

iOS Share Extension - How to access core data

I have a host application which fetches information from Core Data. Now i need a share extension which going to show some information from host app's data.

I have already enabled app group and defined for both Host and Extension , i can access this path from my extension.

 NSURL *storeURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"com.application"];

It only have a /Library path when i get directory and files.

NSArray * files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:url error:nil];
[files enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    NSLog(@"fileName : %@",(NSString *)obj);
}];

My host app's sqlite file is under Documents directory. How can i make this sqlite file available under Shared Container ? Do i need to move whole database ? Any other solution.

Thanks

Upvotes: 3

Views: 914

Answers (1)

Pavel Smejkal
Pavel Smejkal

Reputation: 3599

If you want to access the data directly from the db file, you will have to place it into the shared container. I don't think there is another option, you can't create slink or anything to the host app.

I was solving similar problem and I decided to use group NSUserDefaults to share the contents that I needed in the Shared extension – because it was just couple variables. That might be a simple one solution

Upvotes: 3

Related Questions