ios - 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 显示文件成功
解决方案
推荐阅读
- python - 用 0(零)替换 numpy ndarry 负元素
- wpf - 如何设置 XAML 中静态资源 Image.Source 的大小?
- php - 如何在第三方包路由上添加自己的中间件
- python - 第 90 行的块标记无效:“cart_product_form”,预期为“endblock”。您是否忘记注册或加载此标签?
- reactjs - antd select 处理带有渐变的自定义形状
- typescript - 有没有办法让打字稿推断数组的每个单独索引的类型,而函数中没有类型参数?
- javascript - CSS背景图像不适用于本地
- sql-server - Power Bi:过滤包含字符串的 SQL Server 表
- java - 如何在 Java 中实现(除特定之外的所有内容)的操作?
- php - 在 php 中使用 concat、foreach 和explode 显示问题时出现问题