Non-Sandboxed App built with Xcode could read directory in Big Sur not Monterey

Error Domain=NSCocoaErrorDomain Code=257 "The file “ReceiptScans” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///Users//Documents/ReceiptScans, NSFilePath=/Users//Documents/ReceiptScans, NSUnderlyingError=0x60000178e280 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

I turned off sandboxing to make this work in Big Sur with Xcode 13.1 beta, but when I upgraded to Monterey and Xcode 13.1 I started getting the error again.

let files: [URL] = try FileManager.default.contentsOfDirectory(at: path, includingPropertiesForKeys: nil, options: [FileManager.DirectoryEnumerationOptions.skipsHiddenFiles])

I checked and sandboxing is still turned off. I cleaned the build directory and recompiled. Can't make it work. Have the permissions been changed? Have some API's been changed?

Because sandboxing is turned off I don't think I should have to use any special entitlements.

Replies

The fact that this is failing with EPERM even though App Sandbox is disabled means its very likely you’re hitting a MAC limit. See the discussion is On File System Permissions.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • I'm running the app under Xcode.I've given both the app and Xcode Full Disk Access in the Security & Preferences "Full Disk Access" section.I've added these keys to my plist:

    Privacy - Desktop Folder Usage Description

    Privacy - Documents Folder Usage Description

    I'm trying to open this file: "/Users/papley/Documents/ReceiptScans"

    It still doesn't ask me for permission and still produces this error:

    The file “ReceiptScans” couldn’t be opened because you don’t have permission to view it.

    What am I doing wrong?

Add a Comment

If you create a new test app that tries to read the same file, does it fail in the same way?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"