Ios 穆维特深度链接失败,斯威夫特

Ios 穆维特深度链接失败,斯威夫特,ios,swift,url,swift3,Ios,Swift,Url,Swift3,有没有人成功地从他的应用程序深度链接到moovit某个地方的方向?为什么我不能?!它只是打开应用程序,什么也不做。。。。 如果有人成功地链接到任何地方的方向,请帮助 if UIApplication.shared.canOpenURL(URL(string: "moovit://")!) { // Moovit installed - launch app (with parameters) let MoovitURL: String = "moo

有没有人成功地从他的应用程序深度链接到moovit某个地方的方向?为什么我不能?!它只是打开应用程序,什么也不做。。。。 如果有人成功地链接到任何地方的方向,请帮助

if UIApplication.shared.canOpenURL(URL(string: "moovit://")!) {
            // Moovit installed - launch app (with parameters)
            let MoovitURL: String = "moovit://directions?dest_lat=40.758896&dest_lon=-73.985130&dest_name=TimesSquare&orig_lat=40.735845&orig_lon=-73.990512&orig_name=UnionSquare&auto_run=true&partner_id=<testApp2345>"

            let escapedString = MoovitURL.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
            UIApplication.shared.openURL(URL(string: escapedString!)!)
        }else {
            // Moovit not installed - send to store
            UIApplication.shared.openURL(URL(string: "https://itunes.apple.com/us/app/id498477945")!)

        }
    }
if-UIApplication.shared.canOpenURL(URL(字符串:“moovit://”)){
//Moovit已安装-启动应用程序(带参数)
让MoovitURL:String=”moovit://directions?dest_lat=40.758896&dest_lon=-73.985130&dest_name=timesquare&orig_lat=40.735845&orig_lon=-73.990512&orig_name=UnionSquare&auto_run=true&partner_id=”
让escapedString=MoovitURL.addingPercentEncoding(使用AllowedCharacters:.urlHostAllowed)
UIApplication.shared.openURL(URL(字符串:escapedString!))
}否则{
//未安装Moovit-发送到存储
UIApplication.shared.openURL(URL(字符串):https://itunes.apple.com/us/app/id498477945")!)
}
}

甚至Moovit自己的例子对我也不起作用……怎么了?

试着在Safari中打开这个url,看看它是否有效(它对我有效)。
看起来问题出在代码上,可能尝试不添加PercentEncoding或使用新的openURL API

问题出在.urlHostAllowed参数上。 改为使用.urlQueryAllowed参数将仅转换“?”之后的参数

修复了您的代码:

if UIApplication.shared.canOpenURL(URL(string: "moovit://")!) {
         // Moovit installed - launch app (with parameters)
        let MoovitURL: String = "moovit://directions?dest_lat=40.758896&dest_lon=-73.985130&dest_name=TimesSquare&orig_lat=40.735845&orig_lon=-73.990512&orig_name=UnionSquare&auto_run=true&partner_id=<testApp2345>"

        let escapedString = MoovitURL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
        UIApplication.shared.open(URL(string: escapedString!)!, options: [:], completionHandler: nil)
    }else {
        // Moovit not installed - send to store
        UIApplication.shared.open(URL(string: "https://itunes.apple.com/us/app/id498477945")!, options: [:], completionHandler: nil)

    }
if-UIApplication.shared.canOpenURL(URL(字符串:“moovit://”)){
//Moovit已安装-启动应用程序(带参数)
让MoovitURL:String=”moovit://directions?dest_lat=40.758896&dest_lon=-73.985130&dest_name=timesquare&orig_lat=40.735845&orig_lon=-73.990512&orig_name=UnionSquare&auto_run=true&partner_id=”
让escapedString=MoovitURL.addingPercentEncoding(使用AllowedCharacters:.UrlQueryLowed)
UIApplication.shared.open(URL(字符串:escapedString!),选项:[:],completionHandler:nil)
}否则{
//未安装Moovit-发送到存储
UIApplication.shared.open(URL(字符串):https://itunes.apple.com/us/app/id498477945),选项:[:],completionHandler:nil)
}

你能给出一个代码示例吗?这将非常有用。你可以使用与示例中相同的url,只需复制并粘贴到Safari中即可。另外,请确保您的Moovit应用程序配置为与您尝试打开的位置(在示例中是在纽约)相同的地铁区域。伙计,我尝试了任何东西,但它不起作用。您能帮我更改代码,使其起作用吗?我非常绝望:(没有添加百分比编码,我会崩溃,因为字符串不算作URL…非常感谢你!我感谢你的帮助。我会检查代码是否有效,如果正确,确保标记答案。