iOS 在自定义线程上分派完成块
示例
无论何时使用AFNetworking,都会在AFNetworking提供的自定义线程上调度呼叫。当调用返回到完成块时,它将在主线程上执行。
本示例设置一个自定义线程,该线程分派到完成块:
AFNetworking2.xx:
//用您的名字和DISPATCH_QUEUE_SERIAL创建标志的dispatch_queue_t
dispatch_queue_t myQueue = dispatch_queue_create("com.CompanyName.AppName.methodTest",
DISPATCH_QUEUE_SERIAL);
//AFNetworking的初始AFHTTPRequestOperation
operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
//设置FMDB属性以运行主线程
[operation setCompletionQueue:myQueue];AFNetworking3.xx:
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] init]; [self setCompletionQueue:myQueue];