【问题标题】:URL Scheme for App which is not installed未安装 App 的 URL Scheme
【发布时间】:2012-03-14 19:55:14
【问题描述】:

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

我的问题:如果我的应用程序还没有安装在他们的 iPhone/iPad 上,会发生什么?他们会被引导到 App Store 下载我的应用程序吗?还是会失败?

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

【问题讨论】:

    标签: iphone ios ipad url


    【解决方案1】:

    如果您直接链接到您的应用方案,它将失败。但是,如果您使用可用代码on this StackOverFlow question 链接到网站上的页面,它将尝试打开您的应用程序,如果失败则尝试打开应用程序商店。

    【讨论】:

    • 如果没有安装应用,有没有办法打开网站而不是应用商店?
    【解决方案2】:

    您可以简单地读取方法-(BOOL)openURL:(NSURL*)url 的返回值。如果为否,则表示未安装目标应用程序。以下代码给出了使用导航 url 方案的示例:

    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!)
    }
    

    【讨论】:

    • 当我尝试使用此链接时,在未安装应用程序的情况下,我的链接给我错误“Safari 无法打开页面,因为地址无效”。你能帮忙吗,我会很感激的。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 2015-11-01
    相关资源
    最近更新 更多