我正在尝试让我的应用程序打开苹果地图应用程序,并拉起地址。我尝试了这个:
- (IBAction)openInMaps:(id)sender {
NSString *addressString = @"http://maps.apple.com/?q=1 Infinite Loop, Cupertino, CA";
NSURL *url = [NSURL URLWithString:addressString];
[[UIApplication sharedApplication] openURL:url];
}
还有这个:
- (IBAction)openInMaps:(id)sender {
NSString *addressString = @"http://maps.apple.com/?q=1_Infinite_Loop,_Cupertino,_CA";
NSURL *url = [NSURL URLWithString:addressString];
[[UIApplication sharedApplication] openURL:url];
}
但按钮好像没有连接到任何东西。但是这样做确实有效:
- (IBAction)openInMaps:(id)sender {
NSString *addressString = @"http://maps.apple.com/?q=Cupertino,CA";
NSURL *url = [NSURL URLWithString:addressString];
[[UIApplication sharedApplication] openURL:url];
}
所以,每当有一个空格时,它就无法工作。我该如何打开这个地址?
stringWithFormat:
,直接分配字符串即可。 - rmaddy