1

Restkit を使用して、失敗したリクエストを再試行したい。次のように、デリゲート メソッドからこれを実行しようとしています。

-(void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error{
    NSLog(error.domain);
    NSLog([NSString stringWithFormat:@"%d",error.code]);
    NSLog(error.localizedDescription);
    NSLog(error.localizedFailureReason);
    [request cancel];
    [request reset];
    [request send];
}

ただし、次のエラーが表示されます。

2013-01-14 11:19:29.423 Mobile_ACPL[7893:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to add the same request multiple times'

どうすればこれを実現できますか?

4

1 に答える 1

2

このエラー メッセージはrequest、(再) 送信しようとしている がまだ内部キューにあることを意味します。おそらく、システムが処理するためにより多くの時間を与え、物事cancelを機能さresetせることができます.

これを試してください:

-(void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error{

  [request cancel];
  [request reset];

  dispatch_async(dispatch_get_current_queue(), ^() {
      [request send];
  }
}

それが役に立てば幸い。これが機能しない場合は、(再) 送信を少し遅らせると役立つ場合があります。これは(1.0秒の遅延のために)行うことになります:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 1.0),
               dispatch_get_current_queue(),  ^() {
      [request send];
  });

またはcopy、リクエストをまとめて送信します。

于 2013-01-14T17:40:02.333 に答える