我使用AFNetworking lib中檢索JSON數據,並希望添加如下完成塊:完成排防止AFJSONRequestOperation執行
-(void)getData{
NSString *[email protected]"http://localhost:8080/address/address/address/";
NSURL *url= [ NSURL URLWithString:link];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
arrayofA=[JSON valueForKeyPath:@"a"];
arrayofB=[JSON valueForKeyPath:@"b"];
[[self techTableView] reloadData];
} failure:nil];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
//-- This block gets invoked periodically as the download progress
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(totalBytesRead * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void){
dispatch_async(dispatch_get_main_queue(), ^{
// HUD treatment
});
});
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Completed:");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];
}
當我將完成集團我不再有一個結果,沒有什麼是顯示在屏幕上,並注意到AFJSONRequestOperation
集團沒有執行,我在那裏打印了一個日誌,並沒有顯示。 可能是什麼問題? 非常感謝。
你爲什麼要設置2個不同的成功完成塊?據推測,一個正在運行,一個不是? – Wain
@Wain:我想檢查數組數是否等於0。但'setDownloadProgressBlock'只是爲了進步,不是? – androniennn
重複使用'setCompletionBlockWithSuccess' – Wain