这就是我所拥有的,但它不起作用。
NSString *appleMapsLink = [NSString stringWithFormat: @"http://maps.apple.com/maps?q=%@", _addressLabel.text];
NSURL *url = [NSURL URLWithString:appleMapsLink];
[[UIApplication sharedApplication] openURL:url];
*我的地址标签是从Google地方搜索网址的输出中获得的 _addressLabel.text的示例文本是:旧金山第三街151号 此代码适用于示例字符串,但不适用于我尝试使用的字符串,是否有人知道我做错了什么?
答案 0 :(得分:0)
您需要先将您的网址字符串转换为百分比转义。
NSString *unescaped = [NSString stringWithFormat: @"http://maps.apple.com/maps?q=%@", _addressLabel.text];
NSString *escapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unescaped,
NULL,
CFSTR("!*'();:@&=+$,/?%#[]\" "),
kCFStringEncodingUTF8);
NSURL *url = [NSURL URLWithString:escapedString];
[[UIApplication sharedApplication] openURL:url];
答案 1 :(得分:0)
转义只需要在_addressLabel.text
部分完成,而不是整个网址。