我正在关注AppCoda:Working with Background Fetch Programming并遇到一些错误。我已经创建了基础应用程序,它可以显示来自其源的数据的表格,而且UIRefreshControl
效果很好。
然后我开始创建它的后台获取过程。我已经启用了它的后台功能,在 appDelegate 上设置了最小间隔时间,并实现了application:performFetchWithCompletionHandler:
方法。
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
MyTableViewController *viewController = (MyTableViewController *)self.window.rootViewController;
[viewController fetchNewDataWithCompletionHandler:^(UIBackgroundFetchResult result) {
completionHandler(result);
}];
}
我建立了这个项目,并且仍然运行良好。然后我想通过复制现有项目方案来测试它的后台进程,并启用由于后台获取事件而启动的选项。我按下了运行,由于无法识别选择器,它给了我错误。
[UINavigationController fetchNewDataWithCompletionHandler:]: unrecognized selector sent to instance 0x7fb99280b800
这是我的fetchNewDataWithCompletionHandler
:
- (void)fetchNewDataWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
XMLParser *xmlParser = [[XMLParser alloc] initWithXMLURLString:NewsFeed];
[xmlParser startParsingWithCompletionHandler:^(BOOL success, NSArray *dataArray, NSError *error) {
if (success) {
NSDictionary *latestDict = [dataArray objectAtIndex:0];
NSString *latestTitle = [latestDict objectForKey:@"title"];
NSDictionary *existingDict = [self.arrNewsData objectAtIndex:0];
NSString *existingTilte = [existingDict objectForKey:@"title"];
if ([latestTitle isEqualToString:existingTilte]) {
completionHandler(UIBackgroundFetchResultNoData);
NSLog(@"No new data found");
}
else {
[self performNewFetchedDataActionsWithDataArray:dataArray];
completionHandler(UIBackgroundFetchResultNewData);
NSLog(@"New data was fetched");
}
}
else {
completionHandler(UIBackgroundFetchResultFailed);
NSLog(@"Failed to fetch");
}
}];
}
我不知道这里发生了什么,我的fetchNewDataWithCompletionHandler
?。任何帮助,将不胜感激。谢谢你。