-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: QRCode reader for deep links - WPB-14547 #2187
Open
KaterinaWire
wants to merge
11
commits into
develop
Choose a base branch
from
feat/developer-switch-backend
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−6
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
911bdac
wip
netbe 5a1d168
fix: the issue with a camera view size
KaterinaWire 14ea2f0
clean up
KaterinaWire 64caa89
Merge branch 'develop' into feat/developer-switch-backend
KaterinaWire e9a389f
fix swift lint issues
KaterinaWire de26505
Merge branch 'develop' into feat/developer-switch-backend
KaterinaWire 191bb97
Merge branch 'develop' into feat/developer-switch-backend
KaterinaWire cf0dc4d
Merge branch 'develop' into feat/developer-switch-backend
KaterinaWire 351ff96
run captureSession.startRunning() on the background
KaterinaWire 05406d8
Merge branch 'develop' into feat/developer-switch-backend
KaterinaWire bafd007
Merge branch 'develop' into feat/developer-switch-backend
KaterinaWire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...ios/Wire-iOS/Sources/Developer/DeveloperTools/DeepLinks/QRCodeScannerViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2024 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import AVFoundation | ||
import UIKit | ||
|
||
final class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { | ||
|
||
private var captureSession: AVCaptureSession! | ||
private var previewLayer: AVCaptureVideoPreviewLayer! | ||
var onQRCodeScanned: ((String) -> Void)? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
captureSession = AVCaptureSession() | ||
|
||
guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else { | ||
return | ||
} | ||
|
||
let videoInput: AVCaptureDeviceInput | ||
|
||
do { | ||
videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice) | ||
} catch { | ||
return | ||
} | ||
|
||
if captureSession.canAddInput(videoInput) { | ||
captureSession.addInput(videoInput) | ||
} else { | ||
failed() | ||
return | ||
} | ||
|
||
let metadataOutput = AVCaptureMetadataOutput() | ||
|
||
if captureSession.canAddOutput(metadataOutput) { | ||
captureSession.addOutput(metadataOutput) | ||
|
||
metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main) | ||
metadataOutput.metadataObjectTypes = [.qr] | ||
} else { | ||
failed() | ||
return | ||
} | ||
|
||
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) | ||
previewLayer.frame = view.layer.bounds | ||
previewLayer.videoGravity = .resizeAspectFill | ||
view.layer.addSublayer(previewLayer) | ||
|
||
captureSession.startRunning() | ||
} | ||
|
||
private func failed() { | ||
let alertController = UIAlertController( | ||
title: "Scanning not supported", | ||
message: "Your device doesn't support QR code scanning.", | ||
preferredStyle: .alert) | ||
alertController.addAction(UIAlertAction(title: "OK", style: .default)) | ||
present(alertController, animated: true) | ||
captureSession = nil | ||
} | ||
|
||
override func viewWillDisappear(_ animated: Bool) { | ||
super.viewWillDisappear(animated) | ||
|
||
if captureSession.isRunning { | ||
captureSession.stopRunning() | ||
} | ||
} | ||
|
||
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) { | ||
captureSession.stopRunning() | ||
|
||
if let metadataObject = metadataObjects.first { | ||
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else { return } | ||
guard let stringValue = readableObject.stringValue else { return } | ||
|
||
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate)) | ||
onQRCodeScanned?(stringValue) | ||
} | ||
} | ||
|
||
override var prefersStatusBarHidden: Bool { | ||
return true | ||
} | ||
|
||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { | ||
return .portrait | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-[AVCaptureSession startRunning] should be called from background thread. Calling it on the main thread can lead to UI unresponsiveness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added: