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
p-mazhnik
2022-12-10 13:32:39 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ebf52fa4c6ad9d55bd6db450c42e10a2e4a70112
ebf52fa4
1 parent
869c22ae
fix(ios): fix torch
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
13 deletions
ios/Classes/MobileScanner.swift
ios/Classes/SwiftMobileScannerPlugin.swift
ios/Classes/MobileScanner.swift
View file @
ebf52fa
...
...
@@ -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
()
}
...
...
@@ -207,6 +212,18 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
}
// 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
}
}
/// Analyze a single image
func
analyzeImage
(
image
:
UIImage
,
position
:
AVCaptureDevice
.
Position
,
callback
:
@escaping
BarcodeScanningCallback
)
{
let
image
=
VisionImage
(
image
:
image
)
...
...
ios/Classes/SwiftMobileScannerPlugin.swift
View file @
ebf52fa
...
...
@@ -23,6 +23,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
()
...
...
@@ -145,16 +147,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