AFNetworking 是否在主线程上调用完成块?还是在后台调用,需要我手动将 UI 更新分派到主线程?
使用代码而不是文字,这是来自AFNetworking 文档的示例代码,其中调用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];