私は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
。どんな助けでも大歓迎です。ありがとうございました。