[NSURL URLWithString:] returns nil

时间:2023-11-10 08:53:37

You need to escape the non-ASCII characters in your hardcoded URL as well:

//localisationName is a arbitrary string here
NSString* webName =[localisationName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString* stringURL =[NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@,Montréal,Communauté-Urbaine-de-Montréal,Québec,Canadae&output=csv&oe=utf8&sensor=false", webName];
NSString* webStringURL =[stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url =[NSURL URLWithString:webStringURL];

You can probably remove the escaping of the localisationName since it will be handled by the escaping of the whole string.