首页 > 解决方案 > 在我的 iPhone 文件夹上,如何为我的应用创建文件夹?[iOS 13]

问题描述

当我想从我的应用程序中保存文件时,我正在尝试在文件应用程序中为我的应用程序创建一个文件夹以供访问

在 iOS 12 及更早版本中,我可以通过启用

Application supports iTunes file sharing如下Supports opening documents in place图所示

在此处输入图像描述

自从更新到 iOS 13 后,过去在 iOS 12 中显示的同一文件夹不再显示。

发生了什么变化?如何在 iOS 13 中解决这个问题?

我使用下面的扩展来保存文件:

extension WebViewController:  URLSessionDownloadDelegate {
    func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {

        // create destination URL with the original pdf name
        guard let url = downloadTask.originalRequest?.url else { return }
        let documentsPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
        let destinationURL = documentsPath.appendingPathComponent(url.lastPathComponent)
        // delete original copy
        try? FileManager.default.removeItem(at: destinationURL)
        // copy from temp to Document
        do {
            try FileManager.default.copyItem(at: location, to: destinationURL)
             DispatchQueue.main.asyncAfter(deadline: .now() + 0.2){
            let activityViewController = UIActivityViewController(activityItems: [self.fileName, destinationURL], applicationActivities: nil)
                if(UIDevice.current.userInterfaceIdiom == .pad){
                    if let popOver = activityViewController.popoverPresentationController {
                        popOver.sourceView = self.view
                        popOver.sourceRect = self.view.bounds
                        popOver.barButtonItem = self.navigationItem.rightBarButtonItem
                        self.present(activityViewController, animated: true, completion: nil)
                    }
                }
                else{
                    self.present(activityViewController, animated: true, completion: nil)
                }
            }
        } catch let error {
            print("Copy Error: \(error.localizedDescription)")
        }
    }
}

标签: iosswiftxcodeios13

解决方案


对于那些寻找上述特定问题的答案的人,

更新到 iOS 13.1 似乎可以解决这个问题,所以我不确定这是否是某种错误


推荐阅读