Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 链接不工作。。。为什么? 链接工作不正常: 在线崩溃:_Ios_Swift_Url_Swift3 - Fatal编程技术网

Ios 链接不工作。。。为什么? 链接工作不正常: 在线崩溃:

Ios 链接不工作。。。为什么? 链接工作不正常: 在线崩溃:,ios,swift,url,swift3,Ios,Swift,Url,Swift3,Swift认为您的字符串不是实际的URL,所以它返回了nil。当您试图强制展开它(!)时,它给出了一个错误。如何使它认为它是一个URL?不要回答重复的问题。取而代之的是,投票将它们作为重复项关闭。你必须%逃离你的字符串。我已经做了,这会使崩溃消失,但链接被错误地打开。 let MoovitURL: String = "moovit://nearby?lat=40.758896&lon=-73.985130&title=\(barNameTemplate)&partner_

Swift认为您的字符串不是实际的URL,所以它返回了nil。当您试图强制展开它(
)时,它给出了一个错误。

如何使它认为它是一个URL?不要回答重复的问题。取而代之的是,投票将它们作为重复项关闭。你必须%逃离你的字符串。我已经做了,这会使崩溃消失,但链接被错误地打开。
let MoovitURL: String = "moovit://nearby?lat=40.758896&lon=-73.985130&title=\(barNameTemplate)&partner_id=<nightout>"

        let escapedString = MoovitURL.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
        UIApplication.shared.openURL(URL(string: escapedString!)!)
fatal error: unexpectedly found nil while unwrapping an Optional value
2017-08-14 22:49:35.983585+0300 TestApp[10658:6538686] fatal error: unexpectedly found nil while unwrapping an Optional value
UIApplication.shared.openURL(URL(string: MoovitURL)!)