gpt4 book ai didi

ios7 - AVCaptureMetadataOutput setMetadataObjectTypes : unspported type found

转载 作者:行者123 更新时间:2023-12-04 10:07:06 27 4
gpt4 key购买 nike

我使用 ios7 API 扫描二维码,代码如下:

    AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
[self.captureSession addOutput:output];
[output setMetadataObjectsDelegate:self queue:captureOutputBufferQueue];
output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];

我从 Crashlytics 获得了崩溃信息:
  NSInvalidArgumentException
*** -[AVCaptureMetadataOutput setMetadataObjectTypes:] - unsupported type found. Use - availableMetadataObjectTypes.
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x303b9f83 __exceptionPreprocess + 130
1 libobjc.A.dylib 0x3ab6accf objc_exception_throw + 38
2 AVFoundation 0x2f2f7c29 -[AVCaptureMetadataOutput rectOfInterest]

有人遇到过这个吗?

最佳答案

您必须在设置 metadataObjectTypes 之前将输出添加到 session 。
我遇到错误,并使用以下代码修复它。

@property (nonatomic, strong) AVCaptureMetadataOutput *output;
@property (nonatomic, strong) AVCaptureSession *session;

- (AVCaptureMetadataOutput *)output
{
if (!_output) {
_output = [[AVCaptureMetadataOutput alloc] init];
[_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
}
return _output;
}

- (AVCaptureSession *)session
{
if (!_session) {
_session = [[AVCaptureSession alloc] init];

[_session setSessionPreset:AVCaptureSessionPresetHigh];

if ([_session canAddInput:self.input]) {
[_session addInput:self.input];
}

if ([_session canAddOutput:self.output]) {
[_session addOutput:self.output];

NSArray *typeList = self.output.availableMetadataObjectTypes;
NSLog(@"availableMetadataObjectTypes : %@", typeList);
self.output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];
}
}
return _session;
}

关于ios7 - AVCaptureMetadataOutput setMetadataObjectTypes : unspported type found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25480636/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com