Problem with iphone ios: delegate not responding when using dispatch_async

Here is my code:

MainDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
FetchManager *fetchManager = [FetchManager sharedInstance];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0), ^{
[fetchManager fetchData];
});

//regular code continues

}

FetchData.m (this is a singleton class)

- (id)getInstance { ... }

- (void)fetchData
{
    NSURL *url = [NSURL URLWithString:@"http://www.data.xml"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];

    if (connectionInProgress) {
        [connectionInProgress cancel];
        [connectionInProgress release];
    }

    [xmlData release];
    xmlData = [[NSMutableData alloc] init];

    connectionInProgress = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];  
}

/*and all necessary NSXMLParserDelegate protocol methods are implemented - not shown here*/

Problem: None of the NSXMLParserDelegate protocol methods are running. I do not know why. If I remove "dispatch_async" in the didFinishLaunchingWithOptions method, then everything will work as expected - the NSXMLParserDelegate protocol methods are running.

Does anyone see a problem?

+3
source share
2 answers

Two things jump out:

  • NSURLConnection . , , . dispatch_async(), - , , , NSURLConnection .

  • , . NSURLConnection , , , ? - , ?

+2

Caleb NSURLConnection, . , , - NSOperation, . , Api, NSOperationQueue, iOS5 sendAsynchronousRequest:queue:completionHandler

0

Source: https://habr.com/ru/post/1796437/


All Articles