Parse.com user data extraction exception in iOS 8 Today Extension

I am trying to get a list of PFObjects PFUser to display in an iOS 8 Today widget.

After this blog post from Parse, I included the same application groups and key sharing in the main application and extension in Xcode.

I also included the following in AppDelegatemy main application and viewDidLoadmy Today Extension:

[Parse enableLocalDatastore];
[Parse enableDataSharingWithApplicationGroupIdentifier:@"group.com.me.myapp" containingApplication:@"com.me.myapp"];
[Parse setApplicationId:@"myAppId" clientKey:@"myClientId"];

In widgetPerformUpdateWithCompletionHandlerI built and executed my request:

- (void) widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
      PFQuery *query = [PFQuery queryWithClassName:@"Note"];
      [query whereKey:@"User" equalTo:[PFUser currentUser]];

      [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
         if (!error)
         {
            // check for difference between current and new data
            if([self hasNewData:objects]) {
                // fresh data
                notes = objects;
                [self.tableView reloadData];
                [self updatePreferredContentSize];
                completionHandler(NCUpdateResultNewData);
            } else {
                // Data is the same
                completionHandler(NCUpdateResultNoData);
            }
         } else {
            // Failed
            completionHandler(NCUpdateResultFailed);
         }
      }];
    }
}

The first boot seems to work fine - I can get a list of PFObjects. However, whenever the extension is reloaded a second time, the following exception: enableDataSharingWithApplicationGroupIdentifier:containingApplication:' must be called before 'setApplicationId:clientKey''is called when called enableDataSharingWithApplicationGroupIdentifierin viewDidLoad.

, "" , viewDidLoad .

, , , .

? !

+4
1

if(![Parse isLocalDatastoreEnabled]) {
    [Parse enableLocalDatastore];
    [Parse enableDataSharingWithApplicationGroupIdentifier:@"group.com.me.myapp" containingApplication:@"com.me.myapp"];
    [Parse setApplicationId:@"myAppId" clientKey:@"myClientId"];
}
+1

All Articles