使用 AVFoundation 时如何接受多种类型的条形码
How to accept multiple types of barcodes when using AVFoundation
当我启动 AVFoundation 时,我无法允许几种类型的 barcodes/QR 代码,如果我使用其中一种它有效,但是当我尝试接受两种类型时它只接受最后一种
这里是相关的代码片段
[captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeQRCode]];
[captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeCode39Code]
这就是我添加几种类型接受的方式吗?
当你使用setMetadataObjectTypes:
时,它设置了metadataObjectTypes
,即如果有一个用新的值替换以前的值。它没有 "add/sum" 他们。
因此,不要只对一个对象 ([NSArray arrayWithObject:AVMetadataObjectTypeQRCode]
) 使用 NSArray
,而是使用 arrayWithObjects:
创建一个包含所有类型的数组(注意 "s").
[NSArray arrayWithObjects: AVMetadataObjectTypeQRCode, AVMetadataObjectTypeCode39Code, nil]`
与short hand syntax(等价):
@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeCode39Code]
决赛:
[captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObjects: AVMetadataObjectTypeQRCode, AVMetadataObjectTypeCode39Code, nil];
或
[captureMetadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeCode39Code]];
当我启动 AVFoundation 时,我无法允许几种类型的 barcodes/QR 代码,如果我使用其中一种它有效,但是当我尝试接受两种类型时它只接受最后一种
这里是相关的代码片段
[captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeQRCode]];
[captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeCode39Code]
这就是我添加几种类型接受的方式吗?
当你使用setMetadataObjectTypes:
时,它设置了metadataObjectTypes
,即如果有一个用新的值替换以前的值。它没有 "add/sum" 他们。
因此,不要只对一个对象 ([NSArray arrayWithObject:AVMetadataObjectTypeQRCode]
) 使用 NSArray
,而是使用 arrayWithObjects:
创建一个包含所有类型的数组(注意 "s").
[NSArray arrayWithObjects: AVMetadataObjectTypeQRCode, AVMetadataObjectTypeCode39Code, nil]`
与short hand syntax(等价):
@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeCode39Code]
决赛:
[captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObjects: AVMetadataObjectTypeQRCode, AVMetadataObjectTypeCode39Code, nil];
或
[captureMetadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeCode39Code]];