aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-10-28 22:22:27 +0530
committerRoopesh Chander <roop@roopc.net>2018-10-28 22:22:32 +0530
commit08c855fce6b4c5511d0f9501acb8dab548fd53ba (patch)
tree422fc4388c151abdd1987928abfe7a0ec3a8306e /WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
parentInfo.plist: Indicate that the app shall use the camera (diff)
downloadwireguard-apple-08c855fce6b4c5511d0f9501acb8dab548fd53ba.tar.xz
wireguard-apple-08c855fce6b4c5511d0f9501acb8dab548fd53ba.zip
QR code: Integrate Eric's QR code scanner
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/QRScanViewController.swift25
1 files changed, 11 insertions, 14 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift b/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
index f15d30b..e95ff08 100644
--- a/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
@@ -11,25 +11,21 @@ import CoreData
import UIKit
protocol QRScanViewControllerDelegate: class {
- func didSave(tunnel: Tunnel, qrScanViewController: QRScanViewController)
+ func scannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController)
}
class QRScanViewController: UIViewController {
-
- private var viewContext: NSManagedObjectContext!
- private weak var delegate: QRScanViewControllerDelegate?
+ weak var delegate: QRScanViewControllerDelegate?
var captureSession: AVCaptureSession? = AVCaptureSession()
let metadataOutput = AVCaptureMetadataOutput()
var previewLayer: AVCaptureVideoPreviewLayer!
- func configure(context: NSManagedObjectContext, delegate: QRScanViewControllerDelegate? = nil) {
- viewContext = context
- self.delegate = delegate
- }
-
override func viewDidLoad() {
super.viewDidLoad()
+ self.title = "Scan QR code"
+ self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelTapped))
+
guard let videoCaptureDevice = AVCaptureDevice.default(for: .video),
let videoInput = try? AVCaptureDeviceInput(device: videoCaptureDevice),
let captureSession = captureSession,
@@ -69,8 +65,9 @@ class QRScanViewController: UIViewController {
func scanDidComplete(withCode code: String) {
do {
- let tunnel = try Tunnel.fromConfig(code, context: viewContext)
- delegate?.didSave(tunnel: tunnel, qrScanViewController: self)
+ let tunnelConfiguration = try WgQuickConfigFileParser.parse(code, name: "Scanned")
+ delegate?.scannedQRCode(tunnelConfiguration: tunnelConfiguration, qrScanViewController: self)
+ dismiss(animated: true, completion: nil)
} catch {
scanDidEncounterError(title: "Invalid Code", message: "The scanned code is not a valid WireGuard config file.")
}
@@ -85,6 +82,9 @@ class QRScanViewController: UIViewController {
captureSession = nil
}
+ @objc func cancelTapped() {
+ dismiss(animated: true, completion: nil)
+ }
}
extension QRScanViewController: AVCaptureMetadataOutputObjectsDelegate {
@@ -101,7 +101,4 @@ extension QRScanViewController: AVCaptureMetadataOutputObjectsDelegate {
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
scanDidComplete(withCode: stringValue)
}
-
}
-
-extension QRScanViewController: Identifyable {}