简体   繁体   English

iOS Swift,“在我的iPhone上”文件夹的网址是什么

[英]iOS Swift, what is the url of the “on my iPhone” folder

I need to import to my app some document that have been saved into the "On My iPhone" folder. 我需要将一些已保存到“在我的iPhone上”文件夹中的文档导入到我的应用程序中。 What would be the url of this folder? 该文件夹的网址是什么? (those document (pdf) are saved outside the app by the user and I would like if possible to move/copy them to the app document folder but again I can't find that url. (那些文档(pdf)由用户保存在应用程序外部,我希望尽可能将它们移动/复制到应用程序文档文件夹中,但同样找不到该网址。

Try this code (the way to pick needed document from iPhone Folder: 尝试以下代码(从iPhone文件夹中选择所需文档的方法:

extension YourViewController: UIDocumentInteractionControllerDelegate {
    /// If presenting a top a navigation stack, provide the navigation controller in order to animate in a manner consistent with the rest of the platform
    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
        return self.navigationController ?? self
    }
}

extension YourViewController : UIDocumentPickerDelegate {
    func initDocs() {
        let pickerController = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)

        pickerController.delegate = self
        if #available(iOS 11.0, *) {
            pickerController.allowsMultipleSelection = false
        }
        present(pickerController, animated: false, completion: nil)
    }

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        if let url = urls.first {
            self.handleDoc(url: url) // method in your view controller
        }
    }

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
        print("url = \(url)")
    }

    func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        dismiss(animated: true, completion: nil)
    }
}

In YourViewController call function: YourViewController调用函数中:

@IBAction func importPem(_ sender: UIButton) {

    initDocs()
    UIDocumentInteractionController().presentPreview(animated: true)
}

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

相关问题 在我的 iPhone 文件夹上,如何为我的应用创建文件夹? [iOS 13] - On My iPhone folders, how to create a folder for my app? [iOS 13] CoreData在使用xCode 6的iOS 8 Swift中的我的模拟器上运行但在我的iPhone上不可用 - CoreData works on my simulator in but not on my iPhone in iOS 8 Swift using xCode 6 如何 Flutter 将文件写入 iOS iPhone“在我的手机上查找”文件夹 - How to Flutter write files to iOS iPhone “Find on my phone” Folder iPhone 3上的Swift 3中的Popover - Popover in swift 3 on iphone ios 如何在Swift 3中使用自定义URL方案打开iOS App? - How to open my iOS App with custom URL scheme in Swift 3? iOS Swift不支持的URL - iOS Swift unsupported URL URL 编码 swift IOS - URL Encoding swift IOS 将 sqlite db 从我的应用程序文件夹复制到 ios swift 中的内置文件应用程序文件夹 - Copy sqlite db from my app document folder to builtin file app folder in ios swift 通过 Swift 在 iPhone(iOS)开发中存储/检索用户数据(读/写文件)的正确方法是什么? - What is correct way to store/retrieve user data (read/write files) in iPhone (iOS) dev via Swift? 如何从 iOS Swift 应用程序中读取 iCloud Drive 桌面文件夹中的 pdf 文件? - How do I read a pdf file in my iCloud Drive Desktop folder from within an iOS Swift app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM