0
  1. I am trying to add a today extension to my app.
  2. My app includes a cocoaPod (our own cocoapod) which sets up the core data model for our app.

  3. I setup the today extension to use our pod.

  4. On running the today extension target, I get an error for this line.

NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"MyModel" withExtension:@"momd"]];

The error is that [[NSBundle mainBundle] URLForResource:@"MyModel" withExtension:@"momd"] is nil.

I have set up the group for the app and the extension in the developer store. Wonder why it cannot find the data model in the app bundle?

-- Thanks

alexburtnik
  • 7,661
  • 4
  • 32
  • 70
Dee-Bha
  • 439
  • 1
  • 4
  • 8

1 Answers1

0

You must create app-group for today extension and change storeURL to a location contained in your shared App Group folder:

NSURL *directory = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.YourGroupName"];
NSURL *storeURL = [directory URLByAppendingPathComponent:@"YourAppName.sqlite"];

For swift: https://medium.com/@maximbilan/ios-shared-coredata-storage-for-app-groups-447b4ba43eec#.au9abo8v5

For objective-C: https://github.com/atomicbird/iOS-Extension-Demo

Tuan Pham
  • 621
  • 9
  • 9