From 70a7bd02d7817d62a4d5f5227e5301b89a1f77db Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Tue, 22 Oct 2019 23:57:27 +0200 Subject: [PATCH] Parse and import configuration URL from picker --- CHANGELOG.md | 4 ++++ .../Organizer/ImportedHostsViewController.swift | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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) + } +}