首页 > 解决方案 > iOS 文件系统沙盒

问题描述

正如我从 Apple 文档中了解到的那样,每个应用程序都有沙箱,因此应用程序的本地存储可以在其中保存数据和文件,而其他应用程序无法访问其数据和文件,但我尝试按应用程序创建文件和从中检索文件 URL 并创建另一个应用程序并将文件 URL 传递给它,但新应用程序成功打开此文件,为什么会发生这种情况?根据Apple文档,其他应用程序必须无法打开文件

在第一个应用程序中: 我使用 Alamofire 下载文件

let destination: DownloadRequest.DownloadFileDestination =
            {
            (temporaryURL, response)in                              
            let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask, true)[0]
            let documentsURL = URL(fileURLWithPath: documentsPath, isDirectory: true)
            let tmpURL = documentsURL.appendingPathComponent("wordFile.docx")  
            return (tmpURL, [.removePreviousFile, .createIntermediateDirectories])
          }
 Alamofire.download(urlString, to:
            destination).responseData { response in                  
                    (response.destinationURL?.path)!
//The "response.destinationURL?.path" is: "/Users/user/Library/Developer/CoreSimulator/Devices/A0427AC0-6D5E-4734-A550-73A8224BD54D/data/Containers/Data/Application/4126243E-E166-4311-A950-D8FF49A07991/Documents/wordFile.docx"
                })

在第二个应用程序中: 我从前一个应用程序获取文件路径(response.destinationURL?.path)! 并将其传递给 webView ,但 webView 显示文件成功

标签: iosswiftfilesystemsalamofiresandbox

解决方案


推荐阅读