openURL: with a NSURL containing a formatted NSString isn't working
-
19-09-2019 - |
Question
To open Google Maps with directions, i'm using a formatted NSString inside a NSURL. But it doesn't work with [[UIApplication sharedApplication] openURL:nsurl];
code:
NSString * directionsURL = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%@&saddr=%@", @"Hartenseweg 16, Renkum", @"1 Infinte Loop, Cupertino"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:directionsURL]];
Solution
You need to use [NSString stringByReplacingPercentEscapesUsingEncoding:]
to ensure you get a properly encoded string for a url.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow