views:

17

answers:

0

Hi, I'm trying to use NSMetadataQuery to read in restricted directories and I've encountered some problems: I followed the apple documentation to acquire privileges but the result of the query is empty (while I know it shouldn't). Here's the code I wrote:

    AuthorizationRef myAuthorizationRef;

OSStatus myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &myAuthorizationRef);

AuthorizationItem myItem;

myItem.name = "com.Me.myApp.readPermission";
myItem.valueLength = 0;
myItem.value = NULL;
myItem.flags = 0;

AuthorizationRights myRights;

myRights.count = 1;
myRights.items = &myItem;

AuthorizationFlags myFlags = kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagExtendRights;


myStatus = AuthorizationCopyRights (myAuthorizationRef, &myRight, kAuthorizationEmptyEnvironment, myFlags, NULL);

NSLog(@"%d",myStatus == errAuthorizationSuccess);
[query startQuery];

myStatus = AuthorizationFree (myAuthorizationRef,kAuthorizationFlagDestroyRights);

query is just the NSMetadataQuery pointer initialized in such a way:

        query = [[NSMetadataQuery alloc] init];

    [query setSearchScopes:[NSArray arrayWithObject:@"/read"]];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"kMDItemFSName like '*'"];
    [query setPredicate:predicate];

Only root has the permission to read in /read (in which there are 3 empty files: a,b,c). Even if I start the query only after authentication, the result is an empty array.

Can someone tell me where am I getting wrong? (I'm a little bit confused about authorization..)