I have this method to get the contents of an URL
on TV:
-(void)placeGetRequestForDeveloperID:(NSString *)developerID andRunOnCompletion:(void (^)(NSData *data, NSURLResponse *response, NSError *error))ourBlock {
NSString *urlString = [NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@&entity=software", developerID];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
[session dataTaskWithRequest:request completionHandler:ourBlock];
}
The completion block is never called.
NSURLSession
is allowed on tvOS. Is there something I have to set on the project, like entitlements or something on the Info.plist
to make this work? Is this code OK?
Thanks!
By default, when you create the task, it's suspended. You have to start the task by calling resume
.
[[session dataTaskWithRequest:request completionHandler:ourBlock] resume]