UIManagedDocument saveToURL completeHandler não é chamado - Mensagem de erro: "O leitor não tem permissão para acessar a URL."
Eu tenho um aplicativo antigo que usaUIManagedDocument
para interagir com os dados principais. No entanto, no iOS 11.2 (e possivelmente versões anteriores do iOS 11), osaveToURL:forSaveOperation:completionHandler:
O método parece ter parado de funcionar no dispositivo e no simulador (no entanto,faz ainda funciona no simulador do iOS 10.3.1). Especificamente, no código abaixo docompletionHandler
dentro do primeiroif
A instrução nunca é executada (comoNSLog
mensagens indicam).
- (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;
}
}
Em vez disso, recebo uma mensagem de erro queThe 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.}
Oque esta acontecendo aqui? Alguma sugestão sobre como fazê-lo funcionar novamente no iOS 11?