I am getting following error while resolving Security Scoped Bookmark in my finder sync extension.
Error Domain=NSCocoaErrorDomain Code=259 "The File couldn't be opened because it isn't in the correct format."
and also possibly the related logging:
Failed to read values in CFPrefsPlistSource<0x6080000ee380> (Domain: MyAppGroupName, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null)): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
I am using following code to create Security Scoped bookmark in Container App:
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.mycomp.xyz"];
NSURL * theSelectedFolder = ....selected folder from NSOpenPanel....
NSData *bookmarkData = [theSelectedFolder bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];
[sharedDefaults setObject:bookmarkData forKey:@"BookmarkData"];
[sharedDefaults synchronize];
In Finder Sync Extension, I am using following code:
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.mycomp.xyz"];
NSData *bookmarkData = [sharedDefaults objectForKey:@"BookmarkData"];
BOOL bookmarkDataIsStale;
NSError *err;
NSURL *userSelectedUrl = [NSURL URLByResolvingBookmarkData:bookmarkData options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&bookmarkDataIsStale error:&err];
and i have also added this entitlement key:
com.apple.security.files.bookmarks.app-scope
in both Finder Sync Extension as well as Container app.
I am new to cocoa programming and not being able to find any luck finder the problem.
What am I doing wrong? Can anyone help me out here?
NSFileReadCorruptFileError
, originating askCFURLReadCorruptResourceError
– Brasilin