未调用UIManagedDocument saveToURL completionHandler - 错误消息:“不允许读者访问URL。”

时间:2017-12-17 20:56:30

标签: ios objective-c ios11 uimanageddocument

我有一个使用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中重新运行的任何建议吗?

0 个答案:

没有答案