Sta*_*Rat 5 iphone objective-c barcode-scanner ios
我的 iOS 应用程序中已经有一些条形码扫描代码很多年了。最近,用户开始抱怨它无法与 iPhone 13 Pro 配合使用。
在调查过程中,我似乎应该使用内置的三重摄像头(如果有的话)。这样做确实修复了 iPhone 13 Pro 的问题,但随后又破坏了 iPhone 12 Pro 的问题,而之前的代码似乎运行良好。
您应该如何为所有设备选择合适的相机?在我看来,苹果公司突然让使用这个以前可以工作的代码变得如此困难,这似乎很奇怪。
这是我当前的代码。“后备”部分是代码多年来使用的部分。
_session = [[AVCaptureSession alloc] init];
// Must use macro camera for barcode scanning on newer devices, otherwise the image is blurry
if (@available(iOS 13.0, *)) {
AVCaptureDeviceDiscoverySession * discoverySession =
[AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInTripleCamera]
mediaType:AVMediaTypeVideo
position:AVCaptureDevicePositionBack];
if (discoverySession.devices.count == 0) {
// no BuiltInTripleCamera
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
} else {
_device = discoverySession.devices.firstObject;
}
} else {
// Fallback on earlier versions
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
}
Run Code Online (Sandbox Code Playgroud)
值得庆幸的是,在 reddit 的帮助下,我找到了解决方案,只需替换
AVCaptureDeviceTypeBuiltInTripleCamera
Run Code Online (Sandbox Code Playgroud)
和
AVCaptureDeviceTypeBuiltInWideAngleCamera
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1790 次 |
| 最近记录: |