AFNetworking是否調用主線程上的完成塊?或者它是否在後臺調用,需要我手動將UI更新發送到主線程?在主線程上調用AFNetworking成功/失敗塊嗎?
使用代碼來代替的話,這是從AFNetworking documentation與調用NSLog
示例代碼由UI更新替代:
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
self.label.text = JSON[@"text"];
} failure:nil];
它應該被寫成這樣?
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
dispatch_async(dispatch_get_main_queue(), ^{
self.label.text = JSON[@"text"];
});
} failure:nil];
@tdarr所有的源代碼都可用,看看,你可以知道這一切 – onmyway133