Parse and import configuration URL from picker

This commit is contained in:
Davide De Rosa 2019-10-22 23:57:27 +02:00
parent 9bff8629b3
commit 70a7bd02d7
2 changed files with 19 additions and 1 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Added
- Import host via document picker.
### Changed ### Changed
- Upgrade project to Xcode 11. - Upgrade project to Xcode 11.

View File

@ -72,6 +72,8 @@ class ImportedHostsViewController: UITableViewController {
@IBAction private func openConfigurationFile() { @IBAction private func openConfigurationFile() {
let picker = UIDocumentPickerViewController(documentTypes: ["public.content", "public.data"], in: .import) let picker = UIDocumentPickerViewController(documentTypes: ["public.content", "public.data"], in: .import)
picker.allowsMultipleSelection = false
picker.delegate = self
present(picker, animated: true, completion: nil) present(picker, animated: true, completion: nil)
} }
@ -88,7 +90,7 @@ class ImportedHostsViewController: UITableViewController {
return true return true
} }
private func tryParseURL(_ url: URL, cell: UITableViewCell) -> Bool { private func tryParseURL(_ url: URL, cell: UITableViewCell?) -> Bool {
deselectSelectedRow() deselectSelectedRow()
importer = HostImporter(withConfigurationURL: url, parentViewController: self) importer = HostImporter(withConfigurationURL: url, parentViewController: self)
@ -143,3 +145,15 @@ extension ImportedHostsViewController {
tableView.deleteRows(at: [indexPath], with: .top) 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)
}
}