문제

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.

도움이 되었습니까?

해결책

The recommended method is to obtain the path from the URL, convert to a C string, and then call access (documented in section 2 of man) to check for the permission you require. E.g., in outline to check for read access:

#include <unistd.h>

if (access([[url path] UTF8String], R_OK) == 0)
{
   // have access rights to read
}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top