在iOS 8 Today Extension中获取parse.com用户数据时出现异常 [英] Exception when fetching parse.com user data in iOS 8 Today Extension

查看:128
本文介绍了在iOS 8 Today Extension中获取parse.com用户数据时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to fetch a list of PFObjects of a PFUser to display in the iOS 8 Today Widget.

在此之后博客文章,我在Xcode的主应用程序和扩展程序中启用了相同的App Groups和Keychain Sharing。

Following this blog post by Parse, I've enabled the same App Groups and Keychain Sharing in both my main app and extension in Xcode.

我还在主应用程序的 AppDelegate 中启用了以下内容我的今日延期的viewDidLoad

I've also enabled the following in the AppDelegate of my main app and the viewDidLoad of my Today Extension:

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

widgetPerformUpdateWithCompletionHandler 中,我构建并执行了我的查询:

In widgetPerformUpdateWithCompletionHandler, I constructed and performed my query:

- (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:'必须在'setApplicationId:clientKey''之前调用 enableDataSharingWithApplicationGroupIdentifier 中调用viewDidLoad

The first load seems to work fine - I'm able to get my list of PFObjects. However, whenever the extension reloads a second time, the following exception: enableDataSharingWithApplicationGroupIdentifier:containingApplication:' must be called before 'setApplicationId:clientKey'' is thrown at the enableDataSharingWithApplicationGroupIdentifier call in viewDidLoad.

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

I can replicate this reload by swiping the Notification Center to the "Notifications" tab and swiping it back, which would cause viewDidLoad to be invoked again.

我已经仔细检查了调用方法的顺序是对的,甚至修改了订单,但我仍然在崩溃。

I've double-checked that the order of calling the methods are right, and even tinkered with the order but am still getting the crash.

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

Any ideas? Thanks in advance!

推荐答案

试试这个

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

这篇关于在iOS 8 Today Extension中获取parse.com用户数据时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆