我有一个旧的应用程序使用UIManagedDocument
与核心数据交互。然而,在 iOS 11.2(可能还有更早的 iOS 11 版本)上saveToURL:forSaveOperation:completionHandler:
方法似乎已停止在设备上和模拟器中工作(但是它does仍然可以在 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 中恢复此功能有什么建议吗?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)