iOS and get/setURLBookmark

I’m working on an iOS app that needs to store and load file locations. It seems that the proper way to do this on iOS is to store the bookmarkData in a file or database for later retrieval.

I started down this path, seeing get/setURLBookmark methods in the URL class, but alas they are private… any chance we could have some kind of interface to these without hacking the URL class? Or maybe make them protected?

What I’m working towards is converting the underlying NSData to/from String for storage in a local file or database.

Doh … just realised they are free functions. So I can use them after all :slight_smile:

Ok, so I’ve been trying to get this working today, hoping someone here might be able to shed some light on why it might not be working. I’ve made a few assumptions… (firstly that I need to mess with bookmarks at all…!!)

My objective is to be able to save file URL’s in an XML file on iOS. These could be files stored in the app bundle, or elsewhere/iCloud etc. My understanding is that to do this in a native iOS app, one would store bookmark NSData objects in CoreData via UserDefaults. So I’m trying to coerce JUCE into doing something equivalent. In essence I’m getting the bookmark data from the URL and base64 encoding it so I can save it in an XML file, and reversing the process to create the URL from the string.

Doing it the standard JUCE way seems to work fine in release builds, but not in debug builds.

Update: I ended up rolling my own methods for accessing URL/bookmark data. I can confirm that the correct path stored in the previous run of the app is retrieved with the lastKnownPathFromBookmark method. But the same bookmark fails to resolve a URL, giving an error of “File not found”. I guess at this point I should be talking to iOS devs… :slight_smile:

Code to store the URL:

        URL& url = getMyStoredURL();
        void* bookmarkData = NSURLUtils::bookmarkFromURL(url);
        auto dataSize = NSDataUtils::getSize(bookmarkData);
        MemoryBlock bookmarkMemoryBlock (bookmarkData, dataSize);
        String bookmarkEncoded = bookmarkMemoryBlock.toBase64Encoding();
        // Store the string in the XML... 

Code to retrieve the URL:

    MemoryBlock bookmarkMemoryBlock;
    auto path = NSURLUtils::lastKnownPathFromBookmark(bookmarkMemoryBlock.getData());
    DBG ("decoded bookmark path:" << path);
    auto url = NSURLUtils::URLfromBookmark(bookmarkMemoryBlock.getData());
    DBG ("decoded URL:" << url.toString(false));


Hi, Adam, I got the same issue, wondering did you make it eventually?