Q:

iOS code skipping over dispatch_async

I need to download data from a URL (this prints the data in JSON format) and store it in a "configuration" file for the app in the app's AppDelegate.m file. When I run the app, it simply skips over the dispatch_async code for some reason. Why is this happening and how do I fix this ?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Download the config.json file
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        NSString *configFileUrl = @"http://webserviceurl";
        //NSString *downloadToFile = @"Configuration.json";
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:configFileUrl]];
        [self performSelectorOnMainThread:@selector(writeDataToConfigurationJsonFile:) withObject:data waitUntilDone:YES];
    });

 //More code below

And this is where I am writing the data to a file in the Documents directory of the app:
-(void)writeDataToConfigurationJsonFile:(NSData*)jsonData{

    NSString *content = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

    //get the documents directory:
    NSArray *paths = NSSearchPathForDirectoriesInDomains
    (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    //make a file name to write the data to using the documents directory:
    NSString *fileName = [NSString stringWithFormat:@"%@/Configuration.json", documentsDirectory];

    //save content to the documents directory
    [content writeToFile:fileName
              atomically:YES
                encoding:NSUTF8StringEncoding
                   error:nil];
}

A:

For the purpose of this application, the best way was to use a synchronous request rather than an asynchronous request. Here's the final chunk of code -
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"some url"]];
NSError        *error = nil;
NSURLResponse  *response = nil;
NSData *receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *string = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(@"response");

NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//make a file name to write the data to using the documents directory:
NSString *fileName = [NSString stringWithFormat:@"%@/Configuration.json", documentsDirectory];
//save content to the documents directory

[string writeToFile:fileName
         atomically:YES
           encoding:NSUTF8StringEncoding
              error:nil];

