Parse and import configuration URL from picker
This commit is contained in:
parent
9bff8629b3
commit
70a7bd02d7
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue