1

我正在做一个使用parse版本1.6.5的项目,并且localDataStoreAppDelegate我启用了localDatastore类似

[Parse enableLocalDatastore];
[Parse setApplicationId:@"AppId" clientKey:@"ClientKey"];

在我的情况下,我ViewController有一个条件是应用程序是否第一次运行,如果是第一次,从服务器检索并将所有对象固定到本地。否则从localDatastore我的代码中检索

if ([self isAppLaunchingForFirstTime]) {
    PFQuery *query = [PFQuery queryWithClassName:@"Category"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
        if (error) {
            [[[UIAlertView alloc]initWithTitle:@"Failed!" message:@"error" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil] show];
        } else {
            if (objects.count) {
                [self.categoryArray addObject:objects];
                [self.collectionView reloadData];
                [PFObject pinAllInBackground:objects block:^(BOOL succeeded, NSError *error) {
                    if (succeeded) {
                        NSLog(@"Pinned successfully");
                    }else {
                        [[[UIAlertView alloc]initWithTitle:@"Error" message:@"Pinning" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil] show];
                    }
                }];                    
            } else {
                [[[UIAlertView alloc]initWithTitle:@"Alert!" message:@"No Records" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil] show];
            }
        }
    }];
} else {
    PFQuery *query = [PFQuery queryWithClassName:@"Category"];
    [query fromLocalDatastore];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
        if (error) {
            [[[UIAlertView alloc]initWithTitle:@"Failed!" message:error.description delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil] show];
        } else {
            if (objects.count) {
                [self.categoryArray addObject:objects];
                [self.collectionView reloadData];
            } else {
                [[[UIAlertView alloc]initWithTitle:@"Alert!" message:@"No Records" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil] show];
            }
        }
    }];
}

问题是第一个应用程序成功运行并在 collectionView 中显示检索到的对象,而从第二次开始,该应用程序有一个长时间运行的后台任务,因为我正在从中检索localDataStore它检查网络连接并重试 5 次以获取每个对象。是否localDataStore需要网络连接。

控制台中的错误日志: 这是重复发生 36 次以获取 7 个对象的错误。

[Error]: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x1e56e2a0 
{NSErrorFailingURLStringKey=https://api.parse.com/1/classes/Category, 
NSErrorFailingURLKey=https://api.parse.com/1/classes/Category,
NSLocalizedDescription=The Internet connection appears to be offline.,
NSUnderlyingError=0x1e57fae0 "The Internet connection appears to be offline."}
(Code: 100, Version: 1.6.5)
4

2 回答 2

0

我建议在 Parse 错误报告中报告这一点: https ://www.parse.com/help#

于 2015-03-24T14:54:19.120 回答
0

您的代码应该可以正常工作。但似乎 isAppLaunchingForFirstTime 标志在对象成功固定后未设置

于 2015-03-24T07:39:37.540 回答