Проблема связана с предоставлением доступа к документу моему приложению с помощью функции «Копировать в ...».
Результатом этого действия является призыв:
//TODO: This is where we save to the documents folder I beleive.
func application(_ app: UIApplication, open inputURL: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Ensure the URL is a file URL
guard inputURL.isFileURL else { return false }
print(#function)
// Reveal / import the document at the URL
guard let documentBrowserViewController = window?.rootViewController as? DocumentBrowserViewController else {
print("DocumentBrowserViewController needs to be RootViewController")
return false
}
documentBrowserViewController.revealDocument(at: inputURL, importIfNeeded: true) { (revealedDocumentURL, error) in
//TODO: Handle error with alert
if let error = error {
print("Error: Failed to reveal the document at URL \(inputURL) with error: '\(error)'")
} else {
print("Success.")
}
// Present the Document View Controller for the revealed URL
//documentBrowserViewController.presentDocument(at: revealedDocumentURL!)
}
return true
}
Операторы печати показывают блок: documentBrowserViewController.revealDocument
выполняется без ошибок.
Согласно документации:
Если importIfNeeded имеет значение true, браузер документов вызывает метод documentBrowser (: didImportDocumentAt: toDestinationURL :) своего делегата (или его метод documentBrowser (: failedToImportDocumentAt: error :), если произошла ошибка) перед вызовом обработчика завершения .
Однако ни один из этих двух методов не вызывается.
ПРИМЕЧАНИЯ:
- Я установил documentBrowserViewController в качестве собственного делегата.
- Я не одинок. Форум Apple.
Я неправильно понимаю API? Моя цель - сохранить файл в пользовательских документах, когда он импортируется из внешнего приложения с помощью («копировать в»). Я планировал сделать это за:
documentBrowser(_:didImportDocumentAt:toDestinationURL:)