没有安装的应用程序的URLscheme

简单的问题,我正在开发一个应用程序,将注册自己的URLscheme。 我计划通过一个人最喜欢的QRCode阅读器使用QRCode启动应用程序。

我的问题:如果我的应用程序尚未安装在iPhone / iPad上,会发生什么? 他们将被定向到App Store下载我的应用程序? 还是会失败?

我现在不在我的Mac上,否则我会构build一个testing应用程序来启动我知道没有安装的应用程序的URL。 如果在某人回答之前回到我的Mac,我会用我的结果更新这个问题。

如果您直接链接到您的应用程序scheme,则会失败。 但是,如果您使用此StackOverFlow问题上的代码链接到网站上的某个网页,则会尝试打开您的应用程序,如果失败,则尝试打开应用程序商店。

你可以简单地读取方法的返回值-(BOOL)openURL:(NSURL*)url 。 如果是“否”,则表示目标应用程序未安装。 下面的代码给出了一个使用navigon urlscheme的例子:

 NSString *stringURL = @"navigon://coordinate/NaviCard/19.084443/47.573305"; NSURL *url = [NSURL URLWithString:stringURL]; if([[UIApplication sharedApplication] openURL:url]) { NSLog(@"Well done!"); } else { stringURL = @"https://itunes.apple.com/it/app/navigon-europe/id320279293?mt=8"; url = [NSURL URLWithString:stringURL]; [[UIApplication sharedApplication] openURL:url]; } 

更新Swift 3

 var stringURL = "navigon://coordinate/NaviCard/19.084443/47.573305" var url = URL.init(string: stringURL) if !UIApplication.shared.canOpenURL(url!) { stringURL = "https://itunes.apple.com/it/app/navigon-europe/id320279293?mt=8" url = URL.init(string: stringURL) } if #available(iOS 10.0, *) { UIApplication.shared.open(url!, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url!) }