Issues with bookmarks of files in ubiquity container on iOS

84 Views Asked by At

I have an iOS app using Core Data. The app can save files locally on the device and in iCloud. When I create a URL of the ubiquity container using

    FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")

reading and writing of Core Data files is working fine.

Now I want to store a bookmark of the recently used file in the UserDefaults. I create the bookmark using the standard method url.bookmarkData().

When I resolve the url from the bookmark using

    var isStale = false
    let url = try URL(resolvingBookmarkData: bookMark, bookmarkDataIsStale: &isStale)

it looks identical to the url created with FileManager as discribed above. The file content can be read appropriately. So far so good.

The problem occurs, when the app tries to save the managedObjectContext of my CoreDataStack. The context fires the following error:

Updating max pk failed: authorization denied with userInfo of { NSSQLiteErrorDomain = 23; }

Obviously writing access seems to be denied after resolving a ubiquity container URL from a bookmark and I have no idea to solve this problem.

0

There are 0 best solutions below