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
Navaron Bracke
2023-12-11 14:10:07 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e3942909581f1bf4e69075ee8bcb5ba35721206d
e3942909
1 parent
6f47365a
use default selectors instead of a discovery session
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
5 deletions
ios/Classes/MobileScanner.swift
ios/Classes/MobileScanner.swift
View file @
e394290
...
...
@@ -69,6 +69,43 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
super
.
init
()
}
/// Get the default camera device for the given `position`.
///
/// This function selects the most appropriate camera, when it is available.
private
func
getDefaultCameraDevice
(
position
:
AVCaptureDevice
.
Position
)
->
AVCaptureDevice
?
{
if
#available(iOS 13.0, *)
{
// Find the built-in Triple Camera, if it exists.
if
let
device
=
AVCaptureDevice
.
default
(
.
builtInTripleCamera
,
for
:
.
video
,
position
:
position
)
{
return
device
}
// Find the built-in Dual-Wide Camera, if it exists.
if
let
device
=
AVCaptureDevice
.
default
(
.
builtInDualWideCamera
,
for
:
.
video
,
position
:
position
)
{
return
device
}
}
// Find the built-in Dual Camera, if it exists.
if
let
device
=
AVCaptureDevice
.
default
(
.
builtInDualCamera
,
for
:
.
video
,
position
:
position
)
{
return
device
}
// Find the built-in Wide-Angle Camera, if it exists.
if
let
device
=
AVCaptureDevice
.
default
(
.
builtInWideAngleCamera
,
for
:
.
video
,
position
:
position
)
{
return
device
}
return
nil
}
/// Check if we already have camera permission.
func
checkPermission
()
->
Int
{
let
status
=
AVCaptureDevice
.
authorizationStatus
(
for
:
.
video
)
...
...
@@ -146,11 +183,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
textureId
=
registry
?
.
register
(
self
)
// Open the camera device
if
#available(iOS 13.0, *)
{
device
=
AVCaptureDevice
.
DiscoverySession
(
deviceTypes
:
[
.
builtInTripleCamera
,
.
builtInDualWideCamera
,
.
builtInDualCamera
,
.
builtInWideAngleCamera
],
mediaType
:
.
video
,
position
:
cameraPosition
)
.
devices
.
first
}
else
{
device
=
AVCaptureDevice
.
DiscoverySession
(
deviceTypes
:
[
.
builtInDualCamera
,
.
builtInWideAngleCamera
],
mediaType
:
.
video
,
position
:
cameraPosition
)
.
devices
.
first
}
device
=
getDefaultCameraDevice
(
position
:
cameraPosition
)
if
(
device
==
nil
)
{
throw
MobileScannerError
.
noCamera
...
...
Please
register
or
login
to post a comment