无法打开该文件,因为您没有查看它的权限(真实设备)

The file couldn’t be opened because you don’t have permission to view it (REAL DEVICE)

我知道有人问过类似的问题,但我找不到任何可以解决我的问题的方法。

就我而言,我开发了一个 iOS 应用程序 (Xcode 13.4) 来从我使用 UIDocumentPickerViewController 选择的 CSV 文件中导入和解析数据。在模拟器上一切正常,但是当我 运行 我的 iPhone 上的应用程序时,当我选择一个文件并尝试解析它时,我的应用程序崩溃并出现错误 The file "test.csv" couldn’t be opened because you don’t have permission to view it。我在 Info.plist 中添加了与文档访问相关的所有权限,如下所示:

<key>NSFileProviderDomainUsageDescription</key>
    <string>Description</string>
    <key>UISupportsDocumentBrowser</key>
    <true/>
    <key>NSDesktopFolderUsageDescription</key>
    <string></string>
    <key>NSDownloadsFolderUsageDescription</key>
    <string></string>
    <key>NSFileProviderPresenceUsageDescription</key>
    <string></string>
    <key>NSAppleMusicUsageDescription</key>
    <string></string>
    <key>UIFileSharingEnabled</key>
    <true/>
    <key>NSDocumentsFolderUsageDescription</key>
    <string>Description</string>
    <key>LSSupportsOpeningDocumentsInPlace</key>
    <true/>

但没有任何效果。我错过了什么吗?提前致谢!

如果有人感兴趣,我已经能够通过在实际访问文件之前在文档选择器中调用 url.startAccessingSecurityScopedResource() 来解决它。希望这对您有所帮助!