Skip to content

Commit 7b7a09e

Browse files
Merge pull request #1309 from navaronbracke/fix_avdevice_input_check
fix: check canAddInput for AVCaptureSession
2 parents 7a42274 + ae1c2d0 commit 7b7a09e

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
Improvements:
77
* [Android] Added support for Impeller.
88

9+
Bugs fixed:
10+
* [Apple] Fixed a bug that caused a crash when the capture session could not add the video input.
11+
912
## 7.0.0-beta.5
1013

1114
Improvements:

darwin/mobile_scanner/Sources/mobile_scanner/MobileScannerErrorCodes.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ struct MobileScannerErrorCodes {
1818
// The error code 'CAMERA_ERROR' does not have an error message,
1919
// because it uses the error message from the underlying error.
2020
static let CAMERA_ERROR = "MOBILE_SCANNER_CAMERA_ERROR"
21+
// This error message is used when the active AVCaptureSession cannot add the camera video input.
22+
static let CAMERA_ERROR_CAPTURE_SESSION_INPUT_OCCUPIED_MESSAGE = "The camera video input could not be initialized."
2123
static let GENERIC_ERROR = "MOBILE_SCANNER_GENERIC_ERROR"
2224
static let GENERIC_ERROR_MESSAGE = "An unknown error occurred."
2325
// This message is used with the 'GENERIC_ERROR' error code.

darwin/mobile_scanner/Sources/mobile_scanner/MobileScannerPlugin.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
358358
// Add device input
359359
do {
360360
let input = try AVCaptureDeviceInput(device: device)
361+
362+
if (!(captureSession!.canAddInput(input))) {
363+
result(FlutterError(
364+
code: MobileScannerErrorCodes.CAMERA_ERROR,
365+
message: MobileScannerErrorCodes.CAMERA_ERROR_CAPTURE_SESSION_INPUT_OCCUPIED_MESSAGE,
366+
details: nil))
367+
return
368+
}
369+
361370
captureSession!.addInput(input)
362371
} catch {
363372
result(FlutterError(

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
);
244244
mainGroup = 97C146E51CF9000F007C117D;
245245
packageReferences = (
246-
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */,
246+
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */,
247247
);
248248
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
249249
projectDirPath = "";
@@ -738,7 +738,7 @@
738738
/* End XCConfigurationList section */
739739

740740
/* Begin XCLocalSwiftPackageReference section */
741-
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */ = {
741+
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */ = {
742742
isa = XCLocalSwiftPackageReference;
743743
relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage;
744744
};

0 commit comments

Comments
 (0)