Попробуйте это ...
- (void) serverRequestFetchData: (NSMutableURLRequest *) запрос withCallback: (void (^) (NSArray *, NSError *)) aCallback {
NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
dispatch_sync(dispatch_get_main_queue(), ^{
NSHTTPURLResponse *statusResponse = (NSHTTPURLResponse *)response;
if (statusResponse.statusCode >= 200 && statusResponse.statusCode < 300) {
if (data.length > 0 && error == nil) {
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if (aCallback) {
aCallback(array, nil);
}
} else {
aCallback(@[], error);
}
} else {
NSString *statusMessage = [NSString stringWithFormat:@"Invalid status response code: %ld", (unsigned long)statusResponse.statusCode];
NSError *statusError = [[NSError alloc] initWithDomain:@"com.somedomain" code:10001 userInfo:@{NSLocalizedDescriptionKey : NSLocalizedString(statusMessage, nil)}];
if (aCallback) {
aCallback(@[], statusError);
}
}
});
}];
[dataTask resume];
}
- (void) myRequest {
NSString *jsonRequest = [NSString stringWithFormat:@"{\"access_token\":\"ACCESS_TOKEN_HERE\"}"];
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
NSString *URLString = [NSString stringWithFormat:@"YOUR_FIRST_URL_STRING"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URLString]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", (int)[requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];
[self serverRequestFetchData:request withCallback:^(NSArray *array, NSError *error) {
}];
}