Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Sebastian Roth
2023-06-15 22:09:22 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cd506ebde87ad3219071cb2308b2ba44a64fd205
cd506ebd
1 parent
5aa2c119
Start running the capture session on a background thread
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
7 deletions
example/ios/Runner.xcodeproj/project.pbxproj
ios/Classes/MobileScanner.swift
ios/Classes/SwiftMobileScannerPlugin.swift
example/ios/Runner.xcodeproj/project.pbxproj
View file @
cd506eb
...
...
@@ -204,6 +204,7 @@
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
...
...
ios/Classes/MobileScanner.swift
View file @
cd506eb
...
...
@@ -51,6 +51,8 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
var
detectionSpeed
:
DetectionSpeed
=
DetectionSpeed
.
noDuplicates
private
let
backgroundQueue
=
DispatchQueue
(
label
:
"camera-handling"
)
var
standardZoomFactor
:
CGFloat
=
1
init
(
registry
:
FlutterTextureRegistry
?,
mobileScannerCallback
:
@escaping
MobileScannerCallback
,
torchModeChangeCallback
:
@escaping
TorchModeChangeCallback
,
zoomScaleChangeCallback
:
@escaping
ZoomScaleChangeCallback
)
{
...
...
@@ -118,7 +120,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
/// Start scanning for barcodes
func
start
(
barcodeScannerOptions
:
BarcodeScannerOptions
?,
returnImage
:
Bool
,
cameraPosition
:
AVCaptureDevice
.
Position
,
torch
:
AVCaptureDevice
.
TorchMode
,
detectionSpeed
:
DetectionSpeed
)
throws
->
MobileScannerStartParameter
s
{
func
start
(
barcodeScannerOptions
:
BarcodeScannerOptions
?,
returnImage
:
Bool
,
cameraPosition
:
AVCaptureDevice
.
Position
,
torch
:
AVCaptureDevice
.
TorchMode
,
detectionSpeed
:
DetectionSpeed
,
completion
:
@escaping
(
MobileScannerStartParameters
)
->
())
throw
s
{
self
.
detectionSpeed
=
detectionSpeed
if
(
device
!=
nil
)
{
throw
MobileScannerError
.
alreadyStarted
...
...
@@ -195,24 +197,36 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
}
captureSession
.
commitConfiguration
()
captureSession
.
startRunning
()
backgroundQueue
.
async
{
self
.
captureSession
.
startRunning
()
// Enable the torch if parameter is set and torch is available
// torch should be set after 'startRunning' is called
do
{
try
toggleTorch
(
torch
)
try
self
.
toggleTorch
(
torch
)
}
catch
{
print
(
"Failed to set initial torch state."
)
}
do
{
try
resetScale
()
try
self
.
resetScale
()
}
catch
{
print
(
"Failed to reset zoom scale"
)
}
let
dimensions
=
CMVideoFormatDescriptionGetDimensions
(
device
.
activeFormat
.
formatDescription
)
let
dimensions
=
CMVideoFormatDescriptionGetDimensions
(
self
.
device
.
activeFormat
.
formatDescription
)
return
MobileScannerStartParameters
(
width
:
Double
(
dimensions
.
height
),
height
:
Double
(
dimensions
.
width
),
hasTorch
:
device
.
hasTorch
,
textureId
:
textureId
)
DispatchQueue
.
main
.
async
{
completion
(
MobileScannerStartParameters
(
width
:
Double
(
dimensions
.
height
),
height
:
Double
(
dimensions
.
width
),
hasTorch
:
self
.
device
.
hasTorch
,
textureId
:
self
.
textureId
)
)
}
}
}
/// Stop scanning for barcodes
...
...
ios/Classes/SwiftMobileScannerPlugin.swift
View file @
cd506eb
...
...
@@ -120,8 +120,9 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
let
detectionSpeed
:
DetectionSpeed
=
DetectionSpeed
(
rawValue
:
speed
)
!
do
{
let
parameters
=
try
mobileScanner
.
start
(
barcodeScannerOptions
:
barcodeOptions
,
returnImage
:
returnImage
,
cameraPosition
:
position
,
torch
:
torch
?
.
on
:
.
off
,
detectionSpeed
:
detectionSpeed
)
try
mobileScanner
.
start
(
barcodeScannerOptions
:
barcodeOptions
,
returnImage
:
returnImage
,
cameraPosition
:
position
,
torch
:
torch
?
.
on
:
.
off
,
detectionSpeed
:
detectionSpeed
)
{
parameters
in
result
([
"textureId"
:
parameters
.
textureId
,
"size"
:
[
"width"
:
parameters
.
width
,
"height"
:
parameters
.
height
],
"torchable"
:
parameters
.
hasTorch
])
}
}
catch
MobileScannerError
.
alreadyStarted
{
result
(
FlutterError
(
code
:
"MobileScanner"
,
message
:
"Called start() while already started!"
,
...
...
Please
register
or
login
to post a comment