Saturday, 15 May 2010

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


Does AFNetworking make full block calls on the main thread? Or is it called in the background, do I need to manually send my UI update to the main thread?

Use words instead of codes, the for example code with NSLog is replaced by a UI update:

  AFJSONRequestOperation * operation = [AFJSONRequestOperation JSONRequestOperationWithRequest: request success: ^ (NSURLRequest * request, NSHTTPURLResponse * response, ID JSON) {self.label.text = JSON [@ "text"]; } Failure: zero]; ?   

This is rather

  AFJSONRequestOperation * Operation = [AFJSONRequestOperation should be written like JSONRequestOperationWithRequest: Request Success: ^ (NSURLRequest * request, NSHTTPURLResponse * Feedback ID JSON) {dispatch_async (dispatch_get_main_queue (), ^ {self.label.text = JSON [@ "text"];}); } Failure: zero];    

In AFNetworking 2, a is completionQueue property.

If the sending queue for completionBlock of the operation operation is zero (default), the main queue is used

  OS_OBJECT_USE_OBJC @property #if (nonatomic, strong, nULL) completionQueue dispatch_queue_t. #else @property (nonatomic, assign, empty) dispatch_queue_t closing queue; #endif   

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

To send the dispatch queue if NULL (default), the main queue is used.

  @property (nonatomic, strong) dispatch_queue_t closing queue; @protecti (nonatomic, strong, flexible) after the sender_Q_t;    

No comments:

Post a Comment