简体   繁体   English

在Swift中打开我的iOS应用程序的文档目录

[英]open documents directory of my iOS app in Swift

In my iOS Swift App, I have created files in my App's documents directory through this code: 在我的iOS Swift App中,我通过以下代码在App的documents目录中创建了文件:

let localFileName = String("\(fileName).rtf")
let text = String("text text text")

if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {

    let fileURL = dir.appendingPathComponent(localFileName)
    do {
        try text.write(to: fileURL, atomically: false, encoding: .utf8)
    }
    catch {
    }

}

Now I want to Add a link in my app to this directory where file is created so that user can see files. 现在,我想在我的应用程序中添加一个指向创建文件的目录的链接,以便用户可以看到文件。 Currently I am doing this by this code: 目前,我正在通过以下代码执行此操作:

let importMenu = UIDocumentPickerViewController(documentTypes: [String(kUTTypeRTF)], in: .open)

        importMenu.delegate = self
        importMenu.modalPresentationStyle = .formSheet
        present(importMenu, animated: true, completion: nil)

but this code is for picking documents, not for opening directory, So How I can open my App's Documents directory, not for picking documents, just only for showing documents? 但是此代码用于挑选文档,而不是用于打开目录,那么,如何打开应用程序的Documents目录,而不是挑选文档,而仅用于显示文档?

It is not possible to explore/open a directory in iOS app. 无法在iOS应用中浏览/打开目录。 Apple doesn't provide any api for the same. Apple没有提供相同的任何api。 You need to create it by your own. 您需要自己创建它。

What you can do 你可以做什么

You need to fetch all the files from the specific directory and list them all in either tableview or collection view. 您需要从特定目录中获取所有文件,然后在tableview或collection视图中列出所有文件。

And when user click on the any file, you can show that in web view or based on the file type you can do any specific operations. 并且,当用户单击任何文件时,您可以在Web视图中显示或基于文件类型进行任何特定操作。

So ultimately you need to explore more about FileManager . 因此,最终您需要探索有关FileManager的更多信息。

This class contains what you want. 此类包含您想要的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的iOS App的“文档”目录成为文件? - Why my iOS App's Documents directory became a file? C FOpen()打开文档目录iOS - C FOpen() Open Documents Directory iOS 如何阅读和打开iOS应用程序文档目录中的文件? - How do I read and open files in an iOS app's documents directory? 如何在Swift 3中使用自定义URL方案打开iOS App? - How to open my iOS App with custom URL scheme in Swift 3? 如何创建我的应用程序链接以在 iOS Swift 的浏览器中打开 - How to create my app link to open in browser in iOS Swift iOS App Documents目录被删除 - iOS App Documents directory being dropped 迅速的iOS:在应用程序文档文件夹中创建UIDocument - swift iOS: create UIDocument in app documents folder 如何从其他iOS应用程序读取应用程序文档目录中的文档? - How can I read documents in my app's Document directory from other iOS apps? 我可以在 Xcode 中创建一个 Documents 目录,并通过 UI 将我的 iOS 应用程序的文件放入其中吗? 如果是这样,如何? - Can I create a Documents directory in Xcode, and put files in it for my iOS app through the UI. If so, how? 使用我的ios App iOS 9 Swift 2.2中的路线打开Apple Maps应用程序 - Open Apple Maps App With Directions from my ios App iOS 9 Swift 2.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM