简体   繁体   中英

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

I know that similar questions have been asked but I couldn't find anything that solves my problem.

In my case, I have developed an iOS app (Xcode 13.4) to import and parse data from a CSV file that I pick using an UIDocumentPickerViewController . Everything works fine on simulator, but when I run the app on my iPhone, the moment I pick a file and try to parse it, my app crashes with the error The file "test.csv" couldn't be opened because you don't have permission to view it . I have added every permission that are related with documents access in my Info.plist as follows:

<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/>

But nothing works. Am I missing something? Thanks in advance!

In case someone is interested, I've been able to solve it by calling url.startAccessingSecurityScopedResource() in the document picker before actually accessing the file. Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM