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)
{
if([self hasNewData:objects]) {
notes = objects;
[self.tableView reloadData];
[self updatePreferredContentSize];
completionHandler(NCUpdateResultNewData);
} else {
completionHandler(NCUpdateResultNoData);
}
} else {
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 .
, , , .
? !