1

I have an app with a Today extension. Using App Groups, I am able to have a single repository for both the app and the extension. However, I must be missing something as the solution only partially works. If I am in the App I can add a record and will see that same record in the widget. However, if a change the value of a column, for example, setting a boolean from true to false. The app won't see the change if it were made in the extension and vice versa. I am saving the change to Core Data:

_record?.managedObjectContext?.save()

Using DB Browser, I am able to verify that the change was made; is in the DB. Clearly, I am missing something. Any ideas would be appreciated.

Chazman
  • 89
  • 1
  • 8

1 Answers1

0

Make sure you're using the same db in both sides

- (void)viewDidLoad {
    [super viewDidLoad];

    if ([self.extensionContext respondsToSelector:@selector(setWidgetLargestAvailableDisplayMode:)]) { // iOS 10+
        [self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeExpanded];
    } else {
        self.preferredContentSize = CGSizeMake(0, 110.0); // iOS 10-
    }

    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreAtURL:[MagicalRecord urlAppGroupStore]];
}

As you can see i'm using magical record but I'm specifying to use the share sqlite file

NSString *const kAppGroupIdentifier = @"group.com.carlosduclos.myapp";

+ (NSURL *)urlAppGroupStore {
    NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:kAppGroupIdentifier];
    return [groupURL URLByAppendingPathComponent:@"mydb.sqlite"];
}
carlos21
  • 485
  • 4
  • 9
  • I'm able to get both the app and the widget to see the shared DB using App Groups. But the opposite view only sees additions and deletions not updates. – Chazman Apr 04 '17 at 16:24