Как переименовать файл документа с открытым UIDocument без закрытия и повторного открытия документа? Закрытие (сохранение), перемещение и повторное открытие документа занимает слишком много времени.Переименовать документ без закрытия UIDocument
У меня есть следующий код, который перемещает файл:
NSFileCoordinator* fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[fileCoordinator coordinateWritingItemAtURL:oldPath
options:NSFileCoordinatorWritingForMoving
writingItemAtURL:newPath
options:NSFileCoordinatorWritingForReplacing
error:&coordinatorError
byAccessor:^(NSURL *newURL1, NSURL *newURL2) {
// Rename the file.
NSFileManager* fileManager = [NSFileManager defaultManager];
[fileCoordinator itemAtURL:oldPath willMoveToURL:newPath];
[fileManager moveItemAtURL:newURL1 toURL:newURL2 error:nil];
[fileCoordinator itemAtURL:oldPath didMoveToURL:newPath];
}];
Согласно документации UIDocument
инвентарем presentedItemDidMoveToURL:
обновить его fileURL
(см https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocument_Class/)
Однако, когда вышеуказанный код называется с документ открыт, он висит, предположительно ожидая блокировки на oldPath
(-[NSFileCoordinator(NSPrivate) _blockOnAccessClaim:]
). Работает нормально, если нет жизни UIDocument
.
Связанные, верхний ответ предлагает закрыть и снова открыть UIDocument
: What is the proper way to move a UIDocument to a new location on the file-system