我正在尝试获取 PFUser 的 PFObjects 列表以在 iOS 8 Today Widget 中显示。
按照此博客文章 http://blog.parse.com/announcements/introducing-local-data-sharing-for-apple-watch-and-app-extensions/通过 Parse,我在 Xcode 的主应用程序和扩展程序中启用了相同的应用程序组和钥匙串共享。
我还启用了以下内容AppDelegate
我的主应用程序和viewDidLoad
我的今日扩展:
[Parse enableLocalDatastore];
[Parse enableDataSharingWithApplicationGroupIdentifier:@"group.com.me.myapp" containingApplication:@"com.me.myapp"];
[Parse setApplicationId:@"myAppId" clientKey:@"myClientId"];
In widgetPerformUpdateWithCompletionHandler
,我构建并执行了我的查询:
- (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);
}
}];
}
}
第一次加载似乎工作正常 - 我能够获取 PFObjects 列表。但是,每当扩展程序第二次重新加载时,就会出现以下异常:enableDataSharingWithApplicationGroupIdentifier:containingApplication:' must be called before 'setApplicationId:clientKey''
被扔在enableDataSharingWithApplicationGroupIdentifier
打电话进来viewDidLoad
.
我可以通过将通知中心滑动到“通知”选项卡并将其返回来复制此重新加载,这将导致再次调用 viewDidLoad。
我已经仔细检查了调用方法的顺序是否正确,甚至修改了顺序,但仍然崩溃。
有任何想法吗?提前致谢!