diff --git a/pass/Controllers/PGPKeyFIleImportTableViewController.swift b/pass/Controllers/PGPKeyFIleImportTableViewController.swift index d182f5f..a6c938f 100644 --- a/pass/Controllers/PGPKeyFIleImportTableViewController.swift +++ b/pass/Controllers/PGPKeyFIleImportTableViewController.swift @@ -50,6 +50,15 @@ extension PGPKeyFileImportTableViewController: UIDocumentPickerDelegate { } let fileName = url.lastPathComponent do { + // Start accessing a security-scoped resource. + guard url.startAccessingSecurityScopedResource() else { + // Handle the failure here. + throw AppError.ReadingFile(fileName) + } + + // Make sure you release the security-scoped resource when you are done. + defer { url.stopAccessingSecurityScopedResource() } + let fileContent = try String(contentsOf: url, encoding: .ascii) switch currentlyPicking { case .none: @@ -62,7 +71,8 @@ extension PGPKeyFileImportTableViewController: UIDocumentPickerDelegate { pgpPrivateKeyFile.textLabel?.text = fileName } } catch { - Utils.alert(title: "CannotImportFile".localize(), message: "FileCannotBeImported.".localize(fileName), controller: self) + let message = "FileCannotBeImported.".localize(fileName) | "UnderlyingError".localize(error.localizedDescription) + Utils.alert(title: "CannotImportFile".localize(), message: message, controller: self) } } } diff --git a/pass/Controllers/SSHKeyFileImportTableViewController.swift b/pass/Controllers/SSHKeyFileImportTableViewController.swift index 944b31c..3c6f4dc 100644 --- a/pass/Controllers/SSHKeyFileImportTableViewController.swift +++ b/pass/Controllers/SSHKeyFileImportTableViewController.swift @@ -21,7 +21,7 @@ class SSHKeyFileImportTableViewController: AutoCellHeightUITableViewController { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let cell = tableView.cellForRow(at: indexPath) - let picker = UIDocumentPickerViewController(documentTypes: ["public.data"], in: .open) + let picker = UIDocumentPickerViewController(documentTypes: ["public.data"], in: .import) cell?.isSelected = false guard cell == sshPrivateKeyFile else { return @@ -42,10 +42,20 @@ extension SSHKeyFileImportTableViewController: UIDocumentPickerDelegate { } let fileName = url.lastPathComponent do { + // Start accessing a security-scoped resource. + guard url.startAccessingSecurityScopedResource() else { + // Handle the failure here. + throw AppError.ReadingFile(fileName) + } + + // Make sure you release the security-scoped resource when you are done. + defer { url.stopAccessingSecurityScopedResource() } + privateKey = try String(contentsOf: url, encoding: .ascii) sshPrivateKeyFile.textLabel?.text = fileName } catch { - Utils.alert(title: "CannotImportFile".localize(), message: "FileCannotBeImported.".localize(fileName), controller: self) + let message = "FileCannotBeImported.".localize(fileName) | "UnderlyingError".localize(error.localizedDescription) + Utils.alert(title: "CannotImportFile".localize(), message: message, controller: self) } } }