diff --git a/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift b/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift index 45f6dde..21b50e9 100644 --- a/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift @@ -6,7 +6,7 @@ import CoreData import UIKit protocol QRScanViewControllerDelegate: class { - func scannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController) + func addScannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController, completionHandler: (() ->Void)?) } class QRScanViewController: UIViewController { @@ -119,8 +119,9 @@ class QRScanViewController: UIViewController { if (title.isEmpty) { return } tunnelConfiguration.interface.name = title if let s = self { - s.delegate?.scannedQRCode(tunnelConfiguration: tunnelConfiguration, qrScanViewController: s) - s.dismiss(animated: true, completion: nil) + s.delegate?.addScannedQRCode(tunnelConfiguration: tunnelConfiguration, qrScanViewController: s) { + s.dismiss(animated: true, completion: nil) + } } })) present(alert, animated: true) diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift index 75c3687..780f4d5 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift @@ -214,11 +214,13 @@ extension TunnelsListTableViewController: UIDocumentPickerDelegate { // MARK: QRScanViewControllerDelegate extension TunnelsListTableViewController: QRScanViewControllerDelegate { - func scannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController) { - tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { [weak self] (tunnel, error) in + func addScannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController, + completionHandler: (() ->Void)?) { + tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { (tunnel, error) in if let error = error { - print("Could not add tunnel: \(error)") - self?.showErrorAlert(title: "Could not save scanned config", message: "Internal error") + ErrorPresenter.showErrorAlert(error: error, from: qrScanViewController, onDismissal: completionHandler) + } else { + completionHandler?() } } }