在这里,您的PDF文件存储在应用程序的文档空间中。所以你看不到
文件夹
应用程序。所有保存在
文件
您的应用程序的文件夹可以通过iTunes在
文件共享
但您需要在
幻灯片
第一:
-
已启用ui文件共享
:应用程序支持iTunes文件共享
以便将文档存储在
文件夹
你需要使用
UIDocumentInteractionController
图书馆:
let documentInteractionController = UIDocumentInteractionController()
func downloadPdf(firebaseStoragePath:String){
let ref = Storage.storage().reference().child(firebaseStoragePath)
let documentsURL: NSURL = FileManager.default.urls(for: .temporaryDirectory, in: .userDomainMask).first! as NSURL
let fileURL = documentsURL.appendingPathComponent("doc.pdf")
let task = ref.write(toFile: fileURL!)
task.observe(StorageTaskStatus.success) { (snap) in
DispatchQueue.main.async {
documentInteractionController.url = documentsURL
documentInteractionController.uti = documentsURL.typeIdentifier ?? "public.data, public.content"
documentInteractionController.name = documentsURL.localizedName ?? url.lastPathComponent
documentInteractionController.presentPreview(animated: true)
}
}
}
extension URL {
var typeIdentifier: String? {
return (try? resourceValues(forKeys: [.typeIdentifierKey]))?.typeIdentifier
}
var localizedName: String? {
return (try? resourceValues(forKeys: [.localizedNameKey]))?.localizedName
}
}
不要忘记将这些权限添加到
幻灯片
文件:
-
已启用ui文件共享
:应用程序支持iTunes文件共享
-
LSSupportsOpeningDocumentsInPlace支持
:支持就地打开文档
有关使用
文件夹
和
ui文档交互控制器
你可以查一下这个
blog post
.