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
Julian Steenbakker
2022-12-12 15:57:26 +0100
Browse Files
Options
Browse Files
Download
Plain Diff
Committed by
GitHub
2022-12-12 15:57:26 +0100
Commit
6dc5b094d9fbb6b5622fac7551733d2c4092d8c8
6dc5b094
2 parents
1003c483
062eface
Merge pull request #406 from p-mazhnik/pavel/ios-torch
fix(ios): fix torch
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
31 deletions
CHANGELOG.md
ios/Classes/MobileScanner.swift
ios/Classes/SwiftMobileScannerPlugin.swift
CHANGELOG.md
View file @
6dc5b09
...
...
@@ -22,10 +22,10 @@ Features:
*
Added a new
`placeholderBuilder` function to the `MobileScanner`
widget to customize the preview placeholder.
*
Added
`autoStart`
parameter to MobileScannerController(). If set to false, controller won't start automatically.
*
Added
`hasTorch`
function on MobileScannerController(). After starting the controller, you can check if the device has a torch.
*
[
iOS
]
Support
`torchEnabled`
parameter from MobileScannerController() on iOS
*
[
Web
]
Added ability to use custom barcode scanning js libraries
by extending
`WebBarcodeReaderBase` class and changing `barCodeReader` property in `MobileScannerWebPlugin`
Fixes:
*
Fixes the missing gradle setup for the Android project, which prevented gradle sync from working.
*
Fixes
`MobileScannerController.stop()`
throwing when already stopped.
...
...
@@ -35,6 +35,7 @@ Fixes:
*
Fixes the
`MobileScanner` preview depending on all attributes of `MediaQueryData`
.
Now it only depends on its layout constraints.
*
Fixed a potential crash when the scanner is restarted due to the app being resumed.
*
[
iOS
]
Fix crash when changing torch state
## 3.0.0-beta.2
Breaking changes:
...
...
ios/Classes/MobileScanner.swift
View file @
6dc5b09
...
...
@@ -12,6 +12,7 @@ import MLKitVision
import
MLKitBarcodeScanning
typealias
MobileScannerCallback
=
((
Array
<
Barcode
>
?,
Error
?,
UIImage
)
->
())
typealias
TorchModeChangeCallback
=
((
Int
?)
->
())
public
class
MobileScanner
:
NSObject
,
AVCaptureVideoDataOutputSampleBufferDelegate
,
FlutterTexture
{
/// Capture session of the camera
...
...
@@ -32,6 +33,9 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
/// When results are found, this callback will be called
let
mobileScannerCallback
:
MobileScannerCallback
/// When torch mode is changes, this callback will be called
let
torchModeChangeCallback
:
TorchModeChangeCallback
/// If provided, the Flutter registry will be used to send the output of the CaptureOutput to a Flutter texture.
private
let
registry
:
FlutterTextureRegistry
?
...
...
@@ -43,9 +47,10 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
var
detectionSpeed
:
DetectionSpeed
=
DetectionSpeed
.
noDuplicates
init
(
registry
:
FlutterTextureRegistry
?,
mobileScannerCallback
:
@escaping
MobileScannerCallback
)
{
init
(
registry
:
FlutterTextureRegistry
?,
mobileScannerCallback
:
@escaping
MobileScannerCallback
,
torchModeChangeCallback
:
@escaping
TorchModeChangeCallback
)
{
self
.
registry
=
registry
self
.
mobileScannerCallback
=
mobileScannerCallback
self
.
torchModeChangeCallback
=
torchModeChangeCallback
super
.
init
()
}
...
...
@@ -127,17 +132,6 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
throw
MobileScannerError
.
noCamera
}
// Enable the torch if parameter is set and torch is available
if
(
device
.
hasTorch
&&
device
.
isTorchAvailable
)
{
do
{
try
device
.
lockForConfiguration
()
device
.
torchMode
=
torch
device
.
unlockForConfiguration
()
}
catch
{
throw
MobileScannerError
.
torchError
(
error
)
}
}
device
.
addObserver
(
self
,
forKeyPath
:
#
keyPath
(
AVCaptureDevice
.
torchMode
),
options
:
.
new
,
context
:
nil
)
captureSession
.
beginConfiguration
()
...
...
@@ -169,6 +163,13 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
captureSession
.
commitConfiguration
()
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
)
}
catch
{
print
(
"Failed to set initial torch state."
)
}
let
dimensions
=
CMVideoFormatDescriptionGetDimensions
(
device
.
activeFormat
.
formatDescription
)
return
MobileScannerStartParameters
(
width
:
Double
(
dimensions
.
height
),
height
:
Double
(
dimensions
.
width
),
hasTorch
:
device
.
hasTorch
,
textureId
:
textureId
)
...
...
@@ -198,12 +199,26 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
if
(
device
==
nil
)
{
throw
MobileScannerError
.
torchWhenStopped
}
do
{
try
device
.
lockForConfiguration
()
device
.
torchMode
=
torch
device
.
unlockForConfiguration
()
}
catch
{
throw
MobileScannerError
.
torchError
(
error
)
if
(
device
.
hasTorch
&&
device
.
isTorchAvailable
)
{
do
{
try
device
.
lockForConfiguration
()
device
.
torchMode
=
torch
device
.
unlockForConfiguration
()
}
catch
{
throw
MobileScannerError
.
torchError
(
error
)
}
}
}
// Observer for torch state
public
override
func
observeValue
(
forKeyPath
keyPath
:
String
?,
of
object
:
Any
?,
change
:
[
NSKeyValueChangeKey
:
Any
]?,
context
:
UnsafeMutableRawPointer
?)
{
switch
keyPath
{
case
"torchMode"
:
// off = 0; on = 1; auto = 2;
let
state
=
change
?[
.
newKey
]
as?
Int
torchModeChangeCallback
(
state
)
default
:
break
}
}
...
...
ios/Classes/SwiftMobileScannerPlugin.swift
View file @
6dc5b09
...
...
@@ -55,6 +55,8 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
}
else
if
(
error
!=
nil
){
barcodeHandler
.
publishEvent
([
"name"
:
"error"
,
"data"
:
error
!.
localizedDescription
])
}
},
torchModeChangeCallback
:
{
torchState
in
barcodeHandler
.
publishEvent
([
"name"
:
"torchState"
,
"data"
:
torchState
])
})
self
.
barcodeHandler
=
barcodeHandler
super
.
init
()
...
...
@@ -201,16 +203,4 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
})
result
(
nil
)
}
/// Observer for torch state
public
override
func
observeValue
(
forKeyPath
keyPath
:
String
?,
of
object
:
Any
?,
change
:
[
NSKeyValueChangeKey
:
Any
]?,
context
:
UnsafeMutableRawPointer
?)
{
switch
keyPath
{
case
"torchMode"
:
// off = 0; on = 1; auto = 2;
let
state
=
change
?[
.
newKey
]
as?
Int
barcodeHandler
.
publishEvent
([
"name"
:
"torchState"
,
"data"
:
state
])
default
:
break
}
}
}
...
...
Please
register
or
login
to post a comment