gpt4 book ai didi

ios - 在 iOS 8 Today Extension 中获取 parse.com 用户数据时出现异常

转载 作者:可可西里 更新时间:2023-11-01 06:05:54 25 4
gpt4 key购买 nike

我正在尝试获取 PFUser 的 PFObjects 列表以显示在 iOS 8 Today Widget 中。

关注此blog post通过 Parse,我在 Xcode 的主应用程序和扩展程序中启用了相同的应用程序组和钥匙串(keychain)共享。

我还在主应用程序的 AppDelegate 和 Today Extension 的 viewDidLoad 中启用了以下功能:

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

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'' is throw at the enableDataSharingWithApplicationGroupIdentifier call in viewDidLoad.

我可以通过将通知中心滑动到“通知”选项卡并将其滑动回来来复制此重新加载,这将导致再次调用 viewDidLoad。

我仔细检查了调用方法的顺序是否正确,甚至修改了顺序,但仍然发生崩溃。

有什么想法吗?提前致谢!

最佳答案

试试这个

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

关于ios - 在 iOS 8 Today Extension 中获取 parse.com 用户数据时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30846723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com