2

In my app, when user connects usb device (phone), I use NSWorkspaceDidMountNotification to notify user that the device is detected by performing an NSAlert.

If accepted, app proceed to copy(read) text file contents from device. This worked fine until I enabled AppSandbox. I have enabled usb entitlement but now when app tries to copy, I get following error.

ERROR READING CONTENT OF FILE: Error Domain=NSCocoaErrorDomain Code=257 "The file “Office.txt” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/Volumes/OfficeDrive//documents/Office.txt, NSUnderlyingError=0x600000049390 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

Is it possible to read from an USB device if AppSandbox is enabled.

Napier
  • 105
  • 8

1 Answers1

2

You can only access files the user explicitly grants access to if you're sandboxed:

User-specified files. A sandboxed app (with an appropriate entitlement) automatically obtains access to files in arbitrary locations when those files are explicitly opened by the user or are dragged and dropped onto the application by the user.

(App Sandbox Design Guide)

So you'd have to open a file dialog (probably already pointing to the location you've figured out from the notification) and have the user pick it in order to gain access.

Remotely related SO post:

Community
  • 1
  • 1
cacau
  • 3,606
  • 3
  • 21
  • 42