I have wrote this code to do an HTTP request to a server that sends to me a json string:
-(NSDictionary*)doRequestWithCommand:(NSString*)command andBody:(NSString*)requestBody {
__block NSDictionary *result = nil;
NSURL *URL = [NSURL URLWithString: [NSString stringWithFormat:@"%@%@", PREFIX_URL, command] ];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request setHTTPMethod:REQUEST_TYPE_POST];
[request setHTTPBody:[requestBody dataUsingEncoding:NSUTF8StringEncoding]];
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
__block BOOL done = NO;
while ( !done ) {
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if ( data != nil ) {
result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", [[NSString alloc] initWithData:data encoding:4]);
NSLog(@"len %lu", [[[NSString alloc] initWithData:data encoding:4] length]);
done = YES;
}
dispatch_semaphore_signal(sem);
}];
[dataTask resume];
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
}
return result;
}
This code works fine with iOS 9 and lower, but with iOS 10 no! Practically the answer from the server is cut 1610th character!
I don't know what is the matter! Can you help me?
Thanks