Skip to content

Commit b17e79a

Browse files
committed
UIDocumentBrowserViewController is set to allowsDocumentCreation=true, but fails. Now showing the error message to the user when it happens.
1 parent 8b7214f commit b17e79a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Source/TriangleDrawMain/Browser/BrowserViewController.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,18 @@ extension BrowserViewController: UIDocumentBrowserViewControllerDelegate {
243243

244244
/// Informs the delegate that an import action failed.
245245
func documentBrowser(_ controller: UIDocumentBrowserViewController, failedToImportDocumentAt documentURL: URL, error: Error?) {
246-
// Make sure to handle the failed import appropriately, e.g., by presenting an error message to the user.
247246
if let error = error {
248247
log.error("documentURL: '\(documentURL)' error: '\(error)'")
249248
} else {
250249
log.error("documentURL: '\(documentURL)' error: nil")
251250
}
251+
252+
// Show an error to the user
253+
let errorMessage: String = error.map { "\($0)" } ?? "The error is 'nil'. No info provided."
254+
let alert = UIAlertController(title: "Error in failedToImportDocumentAt", message: errorMessage, preferredStyle: .alert)
255+
let action = UIAlertAction(title: "OK", style: .default) { (_) in }
256+
alert.addAction(action)
257+
controller.present(alert, animated: true)
252258
}
253259

254260
func documentBrowser(_ controller: UIDocumentBrowserViewController, applicationActivitiesForDocumentURLs documentURLs: [URL]) -> [UIActivity] {

0 commit comments

Comments
 (0)