Skip to content

Commit fd42084

Browse files
authored
fix(ios): confirm URL before loading it (#1118)
1 parent a8a4cb3 commit fd42084

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

ios/ReactTestApp/QRCodeScannerViewController.swift

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ final class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutp
5151
super.viewWillAppear(animated)
5252

5353
if captureSession.isRunnable {
54-
captureSession.startRunning()
54+
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
55+
self?.captureSession.startRunning()
56+
}
5557
feedback.prepare()
5658
} else {
5759
let alert = UIAlertController(
@@ -103,11 +105,27 @@ final class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutp
103105

104106
feedback.notificationOccurred(.success)
105107

106-
NotificationCenter.default.post(
107-
name: .didReceiveRemoteBundleURL,
108-
object: self,
109-
userInfo: ["url": urlComponents]
110-
)
108+
guard let presentingViewController = presentingViewController else {
109+
assertionFailure()
110+
return
111+
}
112+
113+
DispatchQueue.main.async {
114+
let alert = UIAlertController(
115+
title: "Is this the right URL?",
116+
message: stringValue,
117+
preferredStyle: .alert
118+
)
119+
alert.addAction(UIAlertAction.Yes { _ in
120+
NotificationCenter.default.post(
121+
name: .didReceiveRemoteBundleURL,
122+
object: presentingViewController,
123+
userInfo: ["url": urlComponents]
124+
)
125+
})
126+
alert.addAction(UIAlertAction.No())
127+
presentingViewController.present(alert, animated: true)
128+
}
111129
}
112130
}
113131
}
@@ -124,6 +142,26 @@ extension Notification.Name {
124142
static let didReceiveRemoteBundleURL = Notification.Name("didReceiveRemoteBundleURL")
125143
}
126144

145+
extension UIAlertAction {
146+
// swiftlint:disable:next identifier_name
147+
static func No(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
148+
UIAlertAction(
149+
title: NSLocalizedString("No", comment: "Negative"),
150+
style: .cancel,
151+
handler: handler
152+
)
153+
}
154+
155+
// swiftlint:disable:next identifier_name
156+
static func Yes(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
157+
UIAlertAction(
158+
title: NSLocalizedString("Yes", comment: "Affirmative"),
159+
style: .default,
160+
handler: handler
161+
)
162+
}
163+
}
164+
127165
extension UIDevice {
128166
var videoOrientation: AVCaptureVideoOrientation {
129167
switch orientation {

0 commit comments

Comments
 (0)