作者:梦露的殇_192 | 来源:互联网 | 2023-01-04 17:38
如何解决《未调用UIManagedDocumentsaveToURLcompletionHandler-错误消息:"不允许读者访问URL."》经验,应该怎么办?
我有一个UIManagedDocument
用于与Core Data交互的旧应用程序.然而在iOS 11.2(甚至更早的iOS 11点发布)的saveToURL:forSaveOperation:completionHandler:
方法似乎已经停止工作无论在设备和模拟器(但它确实在iOS版10.3.1模拟器仍然有效).具体来说,在下面的代码中,completionHandler
内部第一个if
语句永远不会执行(如NSLog
消息所示).
- (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;
}
}
相反,我收到一条错误消息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.}
这里发生了什么?有关如何在iOS 11中重新运行的任何建议吗?