I’m working with bookmarks for the first time and wonder if someone can help me understand the role of relative URL’s when creating Security Scoped Bookmarks. The code snippet below is meant to access a file outside the sandbox that needs to be copied by my app.
dim relativeURL as FolderItem = fileToArchive dim isStale as Boolean dim options as integer = CFBookmarkMBS.kResolutionWithSecurityScope dim url as CFURLMBS = CFBookmarkMBS.ResolveBookmarkDataToCFURLMBS(bookmarkData, options, relativeURL, isStale) // start access if url <> nil then if CFBookmarkMBS.StartAccessingSecurityScopedResource(url) then f = url.file /// do the file copying here CFBookmarkMBS.StopAccessingSecurityScopedResource(url) end if
I’ve successfully created a bookmark of the volume containing the file to be copied and am using it in the variable “bookmarkData”. After reading a lot of documentation, my understanding of the 4th line of code is that the variable, relativeURL, should be set to the file I want to copy so that a CFURLMBS (variable “url”) to it will be created when line 4 runs. But it doesn’t work, it always results in a nil “url” variable. The only way I get a good “url” to the file I want to copy is to set the variable “relativeURL” to “nil” and use a bookmark of its parent directory as the “bookmarkData” variable. Then line 4 runs successfully. I can then change line 7 to “f = url file.child(filename)” and get access to the file and copy it. But I can’t use that technique in the app since there is a long list of files to copy from different volume locations and I don’t want to keep asking the user for permission to access every parent folder.
Any help in getting this strategy to work, or suggestions for different strategies are greatly appreciated. As I said, this is my first run at using SSB’s and I’m sure I’ve made some basic mistakes.