Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a NSURL can be accessed on a Sandboxed app?

I'm writing an OS X application that has an open panel with a preview accessory view.

The problem is that when I select a file that is not on a folder with sandbox permissions I cannot preview it.

Is there any way to tell if a file can would be restricted by the sandbox permissions before trying to open it?

I already tried - (BOOL)checkResourceIsReachableAndReturnError:(NSError **)error of the NSURL class but it returns true even when the file is protected.

like image 487
Bruno Ferreira Avatar asked Dec 13 '22 00:12

Bruno Ferreira


1 Answers

For those who like to have as less as possible Plain-Old-C Lines in the Code:

NSURLIsReadableKey  in NSURL - (BOOL)getResourceValue:(out id *)value forKey:(NSString *)key 

alternatively

NSFileManager - (BOOL)isReadableFileAtPath:(NSString *)path

The sandbox will cause these to return NO if it restricts your access and are merely Cocoa-Wrappers around access(). The sandbox will cause these to return NO if it restricts your access.

like image 72
mahal tertin Avatar answered Mar 05 '23 22:03

mahal tertin