I have an iOS app where I'm attempting to persist and reload bookmark data using UserDefaults. Seems to work OK, but I'm having an issue where sometimes the conversion from the bookmark Data to a URL is failing. It seems to work fine for a period of time (even across the app terminating and relaunching, etc.), but eventually the bookmark data will fail (maybe after a few hours?).
So when resolving the bookmark data like so:
let url = try URL(resolvingBookmarkData: data, bookmarkDataIsStale: &isStale)
A caught exception is thrown with a description: Error Domain=NSCocoaErrorDomain Code=4 "The file doesn’t exist."
I'm storing the bookmark as Data in UserDefaults. I create the bookmark data simply with the following:
let bookmarkData = try url.bookmarkData(options: .minimalBookmark)
Interestingly, if I manually choose the same file again from the document picker, then the original bookmark stored in UserDefaults becomes accessible again.
I've reviewed open source code in GitHub and don't see anything substantially different about my implementations versus others. Looking for any tips or thoughts on what might be causing this issue.