如何使用URL方案打开vlc? 我目前有一个本地视频文件,名称为video,并且收到错误消息:
"Unexpectedly found nil while unwrapping an Optional value"
代码
let vlcURL = "vlc://video.mp4"
let vlcItem = ("vlc", URL(string:vlcURL)!) //i recive the error her
var installedvideoApps = [("Vlc", URL(string:vlcURL)!)]
if UIApplication.shared.canOpenURL(vlcItem.1) {
installedvideoApps.append(vlcItem)
}
let alert = UIAlertController(title: "Selection", message: "Select Video App",
preferredStyle: .actionSheet)
for app in installedvideoApps {
let button = UIAlertAction(title: app.0, style: .default, handler: { _ in
UIApplication.shared.open(app.1, options: [:], completionHandler: nil)
})
alert.addAction(button)
}
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alert.addAction(cancel)
present(alert, animated: true)
答案 0 :(得分:1)
尝试使用URL
向addingPercentEncoding(withAllowedCharacters:)
添加编码。
let vlcURL = "vlc://video.mp4".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
let vlcItem = ("vlc", URL(string:vlcURL)!)