1

I'm having crashes in my sandboxed app related to reading desktops pictures which I can not reproduce on my Mac but I got rejected on the App Store for it crashing and other users have reported crashing.

The desktop pictures are being read from "/Library/Desktop Pictures" or using NSWorkspace's desktopImageURLForScreen method. These work just fine on my Mac but I'm a little confused because I don't know how I'm getting access to "/Library/Desktop Pictures" without the directory being chosen manually in an NSOpenPanel. As for desktopImageURLForScreen I'm not sure if this is sandbox safe depending on where the file is stored on that users screen.

Can anyone verify these 2 methods for getting the desktop picture are safe in all cases or do I need to request the user select the directory where the desktop pictures are stored (even from desktopImageURLForScreen) in a NSOpenPanel?

GenericPtr
  • 677
  • 1
  • 8
  • 18

1 Answers1

0

First, having the sandbox deny access to a URL does not cause a crash - methods will return error indications. So if your app is crashing it is either because you cannot access the URLs, or because you are not testing correctly for failure.

If you wish to quietly access desktop images you can specify the com.apple.security.assets.pictures.read-only entitlement - this will give your app access to common image locations. It does not guarantee that your app can access the URL of the desktop image, just increases the probability. So you must still test for success or failure.

If your program requires access and if silent access fails you can then put up a standard file dialog; with suitably customised prompts, buttons, etc; to request the user grants access to the URL.

HTH

CRD
  • 52,522
  • 5
  • 70
  • 86
  • I'm still not sure if I can expect access to /Library/Desktop Pictures or from other methods though. I don't even want to bother looking in these places if they'll randomly fail on some Macs. I do obviously need to handle the failure better and prevent crashing but I don't want popup a window for new users making them choose "/Library/Desktop Pictures" if I don't need to. Thanks. – GenericPtr Nov 22 '13 at 09:11
  • Add the entitlement, get the URL - the desktop picture can be *anywhere* on the disk, *check* if you have access - either by trying and failing or by using `access()`, if you don't have access only then do you request it from the user. – CRD Nov 22 '13 at 09:24
  • Yeah, I'm just going to make the error handling more robust and pre-request access at startup if it doesn't exist. I'm pretty sure desktopImageURLForScreen is granting persistent access to that directory and "/Library/Desktop Pictures" is accessible outside the container but I can't prove it on my Mac alone. Thanks for the ideas, I appreciate it. – GenericPtr Nov 23 '13 at 01:21