IOS9 xcodeにアップグレードしましたが、私のWebサービスの回答を取得する方法は動作しません。この部分はNSData * urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&応答エラー:&エラー]です。推奨されません。IOS 9 NSURLConnection非推奨
NSString *post =[[NSString alloc] initWithFormat:@"lang=%@&type=ssss",@"en"];
NSURL *url=[NSURL URLWithString:@"http://www.xxxxxxxxxx.com/xxxxxxx/ws/get_xxxxx.php"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSLog(@"esta es la url: %@", postData);
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if ([response statusCode] >=200 && [response statusCode] <300)
{
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:urlData options:kNilOptions error:&error];
NSInteger success = [(NSNumber *) [jsonData objectForKey:@"success"] integerValue];
if(success == 1)
{
if (self.lugares != nil) {
self.lugares = nil;
}
self.lugares = [[NSMutableArray alloc] initWithArray:[jsonData objectForKey:@"lugares"]];
}
else
{
NSLog(@"no hay datos :C");
}
}
else
{
NSLog(@"No encontrado");
}
スイッチ(https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSession_class/)。 – Adam
なぜiOS 8のサポートは既に終了していますか? – rmaddy
[NSURLSession/NSURLConnection HTTPロードがiOS 9で失敗しました]の複製が可能です(http://stackoverflow.com/questions/30739473/nsurlsession-nsurlconnection-http-load-failed-on-ios-9) – Gruntcakes