I have looked on multiple stack overflow posts regarding this issue and attempted to implement those fixes to no avail. Neither of the top two answers from this question worked NSURLSessionDataTask not executing the completion handler block
Here is my very simple code
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSURLSession* session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"https://itunes.apple.com/search?term=apple&media=software"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", json);
}];
[dataTask resume];
}
return 0;
}
I'm never getting any console output.
I have tried instantiating the session in different ways, like
[NSURLSession sharedSession]
which didn't work,
as well as trying to execute the code in the completion block in a different thread
dispatch_sync(dispatch_get_main_queue(), ^{
// Completion code goes here
});
which also didn't work.
I've also tried different URL's. I have no idea why it's not working.