I przeniesieni do IOS9 Xcode, a ja nie działają metody uzyskiwania odpowiedzi na moje usługa ta część NSData * urlData = [NSURLConnection sendSynchronousRequest: wniosek returningResponse: & odpowiedź błąd: & error]; jest przestarzałe.IOS 9 NSURLConnection przestarzałe
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");
}
pozycji [NSURLSession] (https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSession_class/). – Adam
Dlaczego rezygnujesz z obsługi systemu iOS 8? – rmaddy
możliwy duplikat obciążenia HTTP NSURLSession/NSURLConnection na iOS 9] (http://stackoverflow.com/questions/30739473/nsurlsession-nsurlconnection-http-load-failed-on-ios-9) – Gruntcakes