NSURLSessionDataTask acting suspiciously slow

后端 未结 2 1054
慢半拍i
慢半拍i 2021-01-21 00:07

I\'m getting JSON data from the web, parse it, then using it to diplay pins on a map.

Here is method one, which there is no problem with:

NSString *CLIE         


        
相关标签:
2条回答
  • 2021-01-21 00:52

    You need to ensure that UIKit methods will be executed on the main thread.

    The block of the completion handler will be executed on the "delegate queue" (see delegateQueue property of NSURLSession).

    You can accomplish this in two ways: either setup the delegate queue which is the main queue ([NSOperationQueue mainQueue]) or use

    dispatch_async(dispatch_get_main_queue(), ^{ 
        [self loadAnnotationsAndCenter:YES]; 
    });
    

    in your completion block.

    0 讨论(0)
  • 2021-01-21 00:54

    In Swift:

    dispatch_async(dispatch_get_main_queue()) {
    }
    
    0 讨论(0)
提交回复
热议问题