好吧,我已經嘗試了很多不同的方法。我想調用一個JSON API,獲取它的響應,保存鍵值,然後用不同的參數再次調用它。最近,我嘗試在for循環中調用URL方法,當通知發佈時,在觀察者中發佈了一個NSNotification connectionDidFinishLoading:
和NSLogging值。但它只記錄多次最終呼叫的值。多個NSURLConnection調用一個接一個?
我用這個連接初始化...
eventConnection=[[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] delegate:self startImmediately:NO];
[eventConnection scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[eventConnection start];
這是委託方法...
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSNotification *eventNotification=[NSNotification notificationWithName:@"eventsFound" object:nil userInfo:responseDict];
[[NSNotificationQueue defaultQueue]enqueueNotification:eventNotification postingStyle:NSPostNow coalesceMask:NSNotificationCoalescingOnName forModes:nil];
}
任何建議,我怎麼能做到這一點?
[eventConnection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [eventConnection start]; 是不是假設要依次調用api? –
它們按順序啓動,如:啓動第一個;開始第二個;開始第三次...但是你想要的是在第一次*完成*之後開始第二秒(而不是簡單地在第一次開始之後)... – sergio