objective c - startAccessingSecurityScopedResource never returns success -
i'm developing sandboxed mac app store app asks user save files downloads elsewhere. have code folder user (stripping out error checking):
nsopenpanel* openpanel = [nsopenpanel openpanel]; [openpanel setallowsmultipleselection:no]; [openpanel setcanchoosedirectories:yes]; [openpanel setresolvesaliases:yes]; nsinteger result = [openpanel runmodal]; nsarray* urls = [openpanel urls]; nsurl* folderurl = [urls objectatindex:0]; nserror* error; nsdata* bookmakedata = [folderurl bookmarkdatawithoptions:nsurlbookmarkcreationwithsecurityscope includingresourcevaluesforkeys:nil relativetourl:nil error:&error]; _savefolderbookmark = bookmakedata; and when comes time move file folder, have code:
bool isstale; nserror* error; nsurl* savefolder = [nsurl urlbyresolvingbookmarkdata:_savefolderbookmark options:nsurlbookmarkcreationwithsecurityscope relativetourl:nil bookmarkdataisstale:&isstale error:&error]; bool success = [savefolder startaccessingsecurityscopedresource]; // move file somewhere else nsworkspace* workspace = [nsworkspace sharedworkspace]; nsinteger operationtag; bool copied = [workspace performfileoperation:nsworkspacemoveoperation source:[[self getdocumentsfolder] path] destination:[savefolder path] files:[nsarray arraywithobject:filename] tag:&operationtag]; [savefolder stopaccessingsecurityscopedresource]; which lot of code list startaccessingsecurityscopedresource never returns success me, either after getting ulr nsopenpanel or in later run, bookmark data being saved in nsuserdefaults.
in entitlements file, amongst other items, have:
<key>com.apple.security.files.bookmarks.app-scope</key> <true/> is there wrong code?
this 1 easy. you're resolving nsurlbookmarkcreationwithsecurityscope instead of nsurlbookmarkresolutionwithsecurityscope. change line , should work.
(it may not work during same session create bookmark, when have access url, because you're not supposed call in case. on later runs should, of course, because that's whole point.)
Comments
Post a Comment