ios6 から ios7 で Twitter アプリケーションを実行したところ、NSOperation サブクラス (ConnectOperation) 接続のリクエストが setMaxConcurrentOperationCount >3 の場合: didFial: タイムアウトが原因で、興味深いことがわかりました。iOS6では問題なく動作します(現在、必要なだけ操作を追加できます)。私はアイデアがありません助けてください!
[[[KPOperationsManager sharedOperationsManager]getMessagesDownloadQueue] setMaxConcurrentOperationCount:1];
ConnectOperation * op= [[ConnectOperation alloc]initWithEndpoint:@"https://api.twitter.com/1.1/search/tweets.json" andParameters:@"YOLO" andAccount:account andMOC:_mngObjSlaveFetchContext1 andDelegate:self];
ConnectOperation * op2 =[[ConnectOperation alloc]initWithEndpoint:@"https://api.twitter.com/1.1/search/tweets.json" andParameters:@"APPLE" andAccount:account andMOC:_mngObjSlaveContext andDelegate:self];
ConnectOperation * op3 =[[ConnectOperation alloc]initWithEndpoint:@"https://api.twitter.com/1.1/search/tweets.json" andParameters:@"HOUSE" andAccount:account andMOC:_mngObjSlaveFetchContext2 andDelegate:self];
ConnectOperation * op4 =[[ConnectOperation alloc]initWithEndpoint:@"https://api.twitter.com/1.1/search/tweets.json" andParameters:@"EDC" andAccount:account andMOC:_mngObjSlaveFetchContext3 andDelegate:self];
ConnectOperation * op5 =[[ConnectOperation alloc]initWithEndpoint:@"https://api.twitter.com/1.1/search/tweets.json" andParameters:@"IPHONE" andAccount:account andMOC:_mngObjSlaveFetchContext4 andDelegate:self];
[[[OperationsManager sharedOperationsManager]getMessagesDownloadQueue] addOperation:op];
[[[OperationsManager sharedOperationsManager]getMessagesDownloadQueue] addOperation:op2];
[[[OperationsManager sharedOperationsManager]getMessagesDownloadQueue] addOperation:op3];
[[[OperationsManager sharedOperationsManager]getMessagesDownloadQueue] addOperation:op4];
[[[OperationsManager sharedOperationsManager]getMessagesDownloadQueue] addOperation:op5];
@implementation ConnectOperation
- (void)connectionDidFinishLoading: (NSURLConnection*) cn
{ //parse data: NEVER GETS HERE IN IOS 7 , ONLY FAILS ; }
- (void) connection: (NSURLConnection*) cn didFailWithError: (NSError*) error
{ NSLog(@"FAILS DUE TO TIME OUT");
- (void)start {
if( isFinished || [self isCancelled] ) { [self done]; return; }
SLRequest *operation = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/search/tweets.json"] parameters:self.parameters];
[operation setAccount:self.account];
// Use the signed request to start a connection
connection = [NSURLConnection connectionWithRequest:[operation preparedURLRequest]
delegate:self];
if (![NSThread isMainThread]) {
[self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:NO];
return;
}
[self willChangeValueForKey:@"isExecuting"];
isExecuting = YES;
finished = NO;
[self didChangeValueForKey:@"isExecuting"];
[self.connection start];
}
編集:
さらに調査した結果、MaxConcurrentOperationCount:1 を設定しても、4 番目と 5 番目 (op4、op5) の操作がまだタイムアウトしているようです。ただし、最初の 3 つの操作は、期待どおりに連続して実行され、データを取得します。また、MaxConcurrentOperationCount>3 を設定した場合、どの操作も完了せず、すべてタイムアウトになります。