Security Scoped Bookmark - bookmark resolves but still can't access the file

给你一囗甜甜゛ 提交于 2019-12-06 17:34:25

I just stumbled upon the answer accidentally...

For starters, when I was resolving the URL, I was not using the method which allows you to include OPTIONS, so my URL was resolved WITHOUT the security-scope. My original code to resolve was:

try myURL = URL.init(resolvingBookmarkData: loadedMovieDatabase[0].bookmark, bookmarkDataIsStable: &urlResult)!

When I should have been using the version with options here:

try myURL = URL.init(resolvingBookmarkData: loadedMovieDatabase[0].bookmark, Options: URL.bookmarkResolutionOptions.withSecurityScope, relativeTo: nil, bookmarkDataIsStable: &urlResult)!

Basically, I used the first init option Xcode presented in the predictive list with the words "resolvingBookmarkData:" when I should have looked further down the list. (This is how I found my error.)

NOTE also that it's important to use...

URL.bookmarkResolutionOptions.withSecurityScope

and not

URL.bookmarkCreationOptions.withSecurityScope

...when you're resolving your URL or it doesn't appear to work correctly.

Thus ends my frustration with this problem :) I hope this explanation might help others facing this problem!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!