Are Afnetworking Success/Failure Blocks Invoked on the Main Thread

Are AFNetworking success/failure blocks invoked on the main thread?

In AFNetworking 2, AFHTTPRequestOperationManager has a completionQueue property.

The dispatch queue for the completionBlock of request operations.
If NULL (default), the main queue is used.

    #if OS_OBJECT_USE_OBJC
@property (nonatomic, strong, nullable) dispatch_queue_t completionQueue;
#else
@property (nonatomic, assign, nullable) dispatch_queue_t completionQueue;
#endif

In AFNetworking 3, the completionQueue property has been moved to AFURLSessionManager (which AFHTTPSessionManager extends).

The dispatch queue for completionBlock. If NULL (default), the
main queue is used.

@property (nonatomic, strong) dispatch_queue_t completionQueue;
@property (nonatomic, strong, nullable) dispatch_queue_t completionQueue;

AFNetworking 2.0.0-RC2 invokes failure block not on main thread

It seems that it was a bug, as in 2.0 final release the blocks are called on a different way, as you can see in the master branch.

AFNetworking and NSURLConnection on main thread

AFNetworking is running on a child thread not in main thread, but every thread has a main method, which is on the image you post. This is not the main thread.Now tell me What do you want to fix?

AFNetworking 2.0 success block main thread

Notifications are sent synchronously and on the same thread when you post them so you need to switch back to the main thread, preferably before posting (though you could switch after receiving the callback).

You can use either dispatch_async or performSelector:onMainThread: to switch to the main thread.



Related Topics



Leave a reply



Submit