1

When I type the url in a browser it works. When I tried from my program, I have an error. I have no idea why. And you ?

NSString *urlString ;
urlString = @"http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true";
NSURL *url = [NSURL URLWithString:urlString] ;

NSLog(@"--urlString      %@",urlString);
NSLog(@"--absoluteString %@",[url  absoluteString]);
NSLog(@"--host %@",[url  host]);
NSLog(@"--path %@",[url  path]);
NSLog(@"--pathExtension %@",[url  pathExtension]);
NSLog(@"--query %@",[url  query]);
NSLog(@"--scheme %@",[url  scheme]);
NSLog(@"--port %@",[url  port]);
NSLog(@"--parameterString %@",[url  parameterString]);

NSURLRequest *req = [NSURLRequest requestWithURL:url
                                     cachePolicy:NSURLRequestReturnCacheDataDontLoad timeoutInterval:30] ;
NSURLResponse *resp = nil ;

NSError *error = nil ;
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&resp error:&error] ;
NSLog(@"initWithAdresse 1");
if ( error ) {
    NSLog(@"%@",error) ;
}

And I get the following error : Error Domain=NSURLErrorDomain Code=-1008 "resource unavailable" UserInfo=0x6000002e5000 ......

[EDIT] ILario got it !

the solution is to write :

NSURLRequest *req = [NSURLRequest requestWithURL:url
                                     cachePolicy:NSURLCacheStorageAllowedInMemoryOnly timeoutInterval:30] ;

But as I wanted only to get xml from the url, one can use :

parser  = [[NSXMLParser alloc]initWithContentsOfURL:url] ;

There is also :

NSString *result = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error] ;

Thanks for your help

jcezanna56
  • 11
  • 1
  • 4
  • 2
    try to change: cachePolicy:NSURLRequestReturnCacheDataDontLoad with: cachePolicy:NSURLCacheStorageAllowedInMemoryOnly – Ilario Dec 30 '13 at 11:19

0 Answers0