UIManagedDocument saveToURL completeHandler is not called - error message: "The reader is not allowed to access the URL."

I have an old application that uses UIManagedDocument to interact with Core Data. However, on iOS 11.2 (and possibly on earlier versions of iOS 11 points), the saveToURL:forSaveOperation:completionHandler: method seems to have stopped working both on the device and in the simulator (however, it still works in the iOS 10.3.1 simulator). In particular, in the code below, the completionHandler inside the first if never executed (as indicated by the NSLog message).

 - (void)useDemoDocument { NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; url = [url URLByAppendingPathComponent:@"TWL_Document"]; UIManagedDocument *document = [[UIManagedDocument alloc] initWithFileURL:url]; if (![[NSFileManager defaultManager] fileExistsAtPath:[url path]]) { NSLog(@"This Code Executes"); [document saveToURL:url forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { if (success) { NSLog(@"But this is never called"); self.managedObjectContext = document.managedObjectContext; } else { NSLog(@"This also is not called"); } }]; } else if (document.documentState == UIDocumentStateClosed) { [document openWithCompletionHandler:^(BOOL success) { if (success) { self.managedObjectContext = document.managedObjectContext; } }]; } else { self.managedObjectContext = document.managedObjectContext; } } 

Instead, I get the error The reader is not permitted to access the URL. :

 2017-12-17 12:38:14.258936-0800 ToWatchList[1864:542434] [default] [ERROR] Could not get attribute values for item /var/mobile/Containers/Data/Application/2[UUID]/Documents/TWL_Document (n). Error: Error Domain=NSFileProviderInternalErrorDomain Code=1 "The reader is not permitted to access the URL." UserInfo={NSLocalizedDescription=The reader is not permitted to access the URL.} 

What's going on here? Any suggestions on how to do this again in iOS 11?

+6
ios objective-c ios11 uimanageddocument
source share

No one has answered this question yet.

See similar questions:

7
Create UIDocument in iOS 11: Reader Not Allowed to Access URL
0
UIManagedDocuemnt will not open

or similar:

7
Create UIDocument in iOS 11: Reader Not Allowed to Access URL
6
UIManagedDocument Singleton Code openWithCompletionHandler is called twice and crashes
2
FaceBook Connect Login
2
UIManagedDocument CompletionHandler & NSNotification
2
How to make incremental email for UIDocument in iCloud?
one
Getting the UIManagedDocument URL
0
How to ensure that a UIManagedDocument is ready before calling the NSFetchedResultsController method?
0
Error saving master data using UIManagedDocument
0
Sharing an MP3 file with spaces in an Objective-C file
0
Unable to read or create UIManagedDocuments anymore

All Articles