0

私の iPad アプリでは、CloudViewController と呼ばれる ViewController と、SyncServicesController (シングルトン) と呼ばれる「同期エンジン」クラスを使用します。2 つは、SyncServicesController で定義されたデリゲート メソッドと通信します。

私の同期はすべて適切に機能し、CloudViewController に何が起こるか (ログイン、プル、プッシュ、エラーなど) を伝えます。

この問題は、ユーザーがアプリを離れたときに発生します (applicationWillResignActive)。

AppDelegate では、私のコードは次のとおりです。

- (void)applicationWillResignActive:(UIApplication*)application
{
  UIBackgroundTaskIdentifier backgroundIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) { 
    [application endBackgroundTask:backgroundIdentifier];  
    [[SyncServicesController sharedServices] cancelAllRequests]; 
  }]; 

}

そして、SyncServicesController の cancelAllrequests:

- (void)cancelAllRequests
{
  NSLog(@"CancelAllRequests");

  [[HTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"webapp/services/pull"];
  [[HTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"webapp/services/pull_items"];
  [[HTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"webapp/services/pull_image"];
  [[HTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"POST" path:@"webapp/services/push_item"];  
  [[[HTTPClient sharedClient] operationQueue] cancelAllOperations];

}

ユーザーがアプリを離れると、同期は SyncServicesController で呼び出された AFNetworking ブロックの実行を継続します。わかった。しかし、ユーザーがアプリに戻ると、クラッシュします。

たとえば、デリゲートが (EXEC_BAD_ACCESS) と呼ばれる SyncServicesController では、次のようになります。

  AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) 
  {
    [self pullUpdateClientItemsWithServerItems:[JSON valueForKeyPath:@"items"]];
    [delegate syncServicesController:self notifyJob:_T(UPDATING_CLIENT_DATA)];
  } 
  failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
  {
  }];

バックグラウンドに入ったときに CloudViewController が強制終了されたようです... applicationWillResignActive が呼び出されたときに SyncServicesController のデリゲートを管理する最良の方法は何ですか?

4

0 に答える 0