提问人:Rajendra 提问时间:10/11/2023 更新时间:10/11/2023 访问量:28
dispatch_queue_t DISPATCH_QUEUE_SERIAL在 react native ios 项目中 objective-C 不起作用
dispatch_queue_t DISPATCH_QUEUE_SERIAL in react native ios project objective-C not working
问:
我想调用类的委托方法。实现如下,AVCaptureMetadataOutput
//Protocol inheritance
@interface QRScannerVC : UIViewController<AVCaptureMetadataOutputObjectsDelegate>{
//Code of delegate assignment of AVCaptureMetadataOutput
capturedMetadataOutput = [[AVCaptureMetadataOutput alloc] init];
[_captureSession addOutput:capturedMetadataOutput];
capturedMetadataOutput.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];
dispatch_queue_t dispatchQueue = dispatch_queue_create("qrQueue", DISPATCH_QUEUE_SERIAL);
//Delegate method assignment
[capturedMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue];
Delegate method,
- (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
if (metadataObjects != nil && metadataObjects.count > 0) {
AVMetadataMachineReadableCodeObject *metadataObject = [metadataObjects objectAtIndex:0];
if ([[metadataObject type] isEqualToString:AVMetadataObjectTypeQRCode]) {
[_labelStatus performSelectorOnMainThread:@selector(setText:) withObject:[metadataObject stringValue] waitUntilDone:NO];
[self performSelectorOnMainThread:@selector(stopReading) withObject:nil waitUntilDone:NO];
_isReading = NO;
}
}
根据 apple 文档方法,必须在串行队列上调用才能进行连续流式处理。根据 react native 文档,如果操作需要很长时间才能完成,我们可以调用我们的方法。capturedMetadataOutput:setMetadataObjectsDelegate:queue
但就我而言,方法不调用。如果我在纯 iOS 原生 Objective-C 项目中使用相同的代码,那么它会很好用。
不明白什么是React native中的问题。capturedMetadataOutput:setMetadataObjectsDelegate:queue
答: 暂无答案
评论
_captureSession
QRScannerVC
@property(strong, nonatomic) AVCaptureSession *captureSession