diff --git a/CHANGELOG.md b/CHANGELOG.md index ab4e91de..64487e97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Import host via document picker. + ### Changed - Upgrade project to Xcode 11. diff --git a/Passepartout-iOS/Scenes/Organizer/ImportedHostsViewController.swift b/Passepartout-iOS/Scenes/Organizer/ImportedHostsViewController.swift index f9bff091..225bc24b 100644 --- a/Passepartout-iOS/Scenes/Organizer/ImportedHostsViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/ImportedHostsViewController.swift @@ -72,6 +72,8 @@ class ImportedHostsViewController: UITableViewController { @IBAction private func openConfigurationFile() { let picker = UIDocumentPickerViewController(documentTypes: ["public.content", "public.data"], in: .import) + picker.allowsMultipleSelection = false + picker.delegate = self present(picker, animated: true, completion: nil) } @@ -88,7 +90,7 @@ class ImportedHostsViewController: UITableViewController { return true } - private func tryParseURL(_ url: URL, cell: UITableViewCell) -> Bool { + private func tryParseURL(_ url: URL, cell: UITableViewCell?) -> Bool { deselectSelectedRow() importer = HostImporter(withConfigurationURL: url, parentViewController: self) @@ -143,3 +145,15 @@ extension ImportedHostsViewController { tableView.deleteRows(at: [indexPath], with: .top) } } + +extension ImportedHostsViewController: UIDocumentPickerDelegate { + func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { + } + + func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { + guard let url = urls.first else { + return + } + _ = tryParseURL(url, cell: nil) + } +}