我正在做一个使用parse
版本1.6.5的项目,并且localDataStore
在AppDelegate
我启用了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)