App Sandbox: document-scoped bookmark not resolving; not returning any error

前端 未结 1 2123
礼貌的吻别
礼貌的吻别 2020-12-10 11:53

I\'m sandboxing my app, and trying to allow for import/export of multiple files, using an XML file to refer to them. To allow my app (or another sandboxed app) access to the

相关标签:
1条回答
  • 2020-12-10 12:29

    In your Gist code, change the following line in AppDelegate.m (line 61):

    [xmlTextFileData writeToURL:savePanel.URL atomically:YES];
    

    to

    [xmlTextFileData writeToURL:savePanel.URL atomically:NO];
    

    Your code will then work.

    The reason for this is likely the same reason for which it is necessary to have an existing (but empty) file that will contain the document-scoped bookmarks before calling [anURL bookmarkDataWithOptions]: While creating the NSData instance, the ScopedBookmarkAgent adds something (like a tag, probably an extended file attribute) to that file.

    If you write data (i.e. the bookmark URLs) to that file atomically, in fact they're written not directly to the file but first to a temporary file that is renamed if the write operation was successful. It seems that the tag that has been added to the (empty, but existing) file that will contain the bookmarks is getting lost during this process of writing to a temporary file and then renaming it (and thereby likely deleting the original, empty file).

    By the way: It shouldn't be necessary to create app-scoped bookmarks before passing the respective URLs to the xml file containing the document-scoped bookmarks.

    Addition: com.apple.security.files.bookmarks.collection-scope has been renamed to com.apple.security.files.bookmarks.document-scope in 10.7.4.

    0 讨论(0)
提交回复
热议问题