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 14:47:29 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ccdc3c6208ad5346ea75fc03b3da192420dda0bb
ccdc3c62
1 parent
ebf52fa4
fix(ios): fix initial torch state
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
11 deletions
ios/Classes/MobileScanner.swift
ios/Classes/MobileScanner.swift
View file @
ccdc3c6
...
...
@@ -132,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
()
...
...
@@ -174,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
)
...
...
@@ -203,6 +199,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
if
(
device
==
nil
)
{
throw
MobileScannerError
.
torchWhenStopped
}
if
(
device
.
hasTorch
&&
device
.
isTorchAvailable
)
{
do
{
try
device
.
lockForConfiguration
()
device
.
torchMode
=
torch
...
...
@@ -211,6 +208,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
throw
MobileScannerError
.
torchError
(
error
)
}
}
}
// Observer for torch state
public
override
func
observeValue
(
forKeyPath
keyPath
:
String
?,
of
object
:
Any
?,
change
:
[
NSKeyValueChangeKey
:
Any
]?,
context
:
UnsafeMutableRawPointer
?)
{
...
...
Please
register
or
login
to post a comment