Nsurl return nil when i am selecting iPhone language except English
i m calling default map app. from my application but for example when i select Portugal language on my iphone for current location NSURL return nil. I already used UTF8encoding and percentage encapsulate as follows:-
NSString *encodedURLString = [urlString stringByAddingPercentEscapesUsin开发者_如何学PythongEncoding:NSASCIIStringEncoding];
//where urlString has value http://maps.google.com/maps?saddr=Localiza\u00e7\u00e3o+actual&daddr=28.6522907,77.1929857
NSURL *URL = [NSURL URLWithString:encodedURLString];
[[UIApplication sharedApplication] openURL:URL];
i already try NSUTF8Encoding instead NSASCIIStringEncoding but nothing helped. thanx for any help.
You are percent-encoding the entire URL.
This turns http://www.google.com
into http%3A//www.google.com
, which is a malformed URL.
From the NSURL Class Reference:
Return Value: An NSURL object initialized with URLString. If the string was malformed, returns nil.
Ergo, you are receiving nil.
What you want to do is this:
NSString *path = @"http://maps.google.com/maps";
NSString *query = @"saddr=Localiza\u00e7\u00e3o+actual&daddr=28.6522907,77.1929857";
query = [query stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString *url = [NSString stringWithFormat: @"%@?%@", path, query];
NSURL *URL = [NSURL URLWithString: url];
[[UIApplication sharedApplication] openURL: URL];
精彩评论