如何从iPhone应用程序启动另一个应用程序

我正在开发iPhone应用程序中的地图应用程序。

我有一个buttongo

当用户在这个方法中点击这个button时,我想检查用户是否已经在他的iphone上安装了waze应用程序。 如果是,那么导航到waze应用程序,否则打开iPhone的默认地图应用程序。

试着这样做:

 NSString *wazeAppURL = @"waze://"; NSString *mapsAppURL = @"maps://"; BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:wazeAppURL]]; NSString *url = canOpenURL ? wazeAppURL : mapsAppURL; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; 

在这里, canOpenURL允许你testing你的iPhone上是否安装了Waze应用程序。 如果iPhone可以打开urlwaze://这意味着你已经有了应用程序,它将启动它。 否则,它将启动默认的地图应用程序。 Safari不会被调用。

要打开一个应用程序,你需要打电话

 BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"app://"]]; if ( canOpenUrl ) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; 

要查找所有url,请转到此页面: http : //handleopenurl.com/

特别是对于wa,, 请http://handleopenurl.com/scheme/waze

希望这可以帮助。

iOS使用URLscheme来启动其他应用程序。

看到这里http://mobiledevelopertips.com/cocoa/launching-other-apps-within-an-iphone-application.html

它传言苹果可能提供更紧密的整合在未来,但我不会指望它。

请注意,在iOS上,您还可以导航到Google地图 – 并传递查询string或地址。 以下是导航到特定地理点的一个示例:

 if (self.mapView.userLocation.location) { NSString *urlAsString = [NSString stringWithFormat:@"comgooglemaps://?q=%f,%f", self.mapView.userLocation.location.coordinate.latitude, self.mapView.userLocation.location.coordinate.longitude]; if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlAsString]]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlAsString]]; } } 

只是一个提高用户体验的build议。