swift 找不到用于从iOS上的另一个应用程序中打开文件应用程序的专用URL

gijlo24d  于 2022-12-28  发布在  Swift
关注(0)|答案(2)|浏览(130)

我需要从我的应用程序中打开"文件"应用程序。这是一个内部应用程序,不会出现在应用程序商店中,因此我不担心尝试使用私有URL。
我试过了

"App-Prefs:root=files"
"App-Prefs:root=FILES"
"App-Prefs:root=Files"

let url = URL.init(string: "App-Prefs:root=Files")!
UIApplication.shared.open(url, options: [:]) { (Bool) in
    print("opened")
}

根据字符串的不同,它要么不会打开任何东西,要么打开设置应用程序。

cczfrluj

cczfrluj1#

根据this线程,您可以使用shareddocuments://作为URLScheme打开文件应用程序。您可以在this文档中的使用URL方案与应用程序通信一节中阅读有关如何使用URLSchemes的更多信息。

eqfvzcg8

eqfvzcg82#

对于任何寻找代码的人:

// give your initial URL as fileUrl
let sharedPath = fileUrl.absoluteString.replacingOccurrences(of: "file://", with: "shareddocuments://")
                                guard let sharedUrl = URL(string: sharedPath) else {
                                    return
                                }
     UIApplication.shared.open(sharedUrl)

相关问题