我想创建一个自定义键盘,充当条码扫描器.
我已经做了整个编码,但输出不如预期的那样:我被要求摄像机的许可(第一次),但摄像头没有发送视频.
我已经做了整个编码,但输出不如预期的那样:我被要求摄像机的许可(第一次),但摄像头没有发送视频.
我想,出于安全考虑,键盘可能会有一些限制?
1.打开火炬
-(void) turnFlashOn
{
AVCaptureDevice *flashLight = [AVCaptureDevice
defaultDeviceWithMediaType:AVMediaTypeVideo];
if([flashLight isTorchAvailable] && [flashLight
isTorchModeSupported:AVCapturetorchModeOn])
{
BOOL success = [flashLight lockForConfiguration:nil];
if(success){
NSError *error;
[flashLight setTorchMode:AVCapturetorchModeOn];
[flashLight setTorchModeOnWithLevel:1.0 error:&error];
NSLog(@"Error: %@",error);
[flashLight unlockForConfiguration];
NSLog(@"flash turned on -> OK");
}
else
{
NSLog(@"flash turn on -> ERROR");
}
}
}
这给我这个日志输出,但闪光灯没有任何反应:
Error: (null) flash turned on -> OK
2.)扫描条形码(viewDidLoad的一部分)
// SCANNER PART
self.captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];
if(videoInput)
[self.captureSession addInput:videoInput];
else
NSLog(@"Error: %@",error);
AVCaptureMetadataOutput *MetadataOutput = [[AVCaptureMetadataOutput alloc] init];
[self.captureSession addOutput:MetadataOutput];
[MetadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[MetadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode,AVMetadataObjectTypeEAN13Code]];
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
camView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
previewLayer.frame = camView.layer.bounds;
[camView.layer addSublayer:previewLayer];
self.keyboard.barcodeView.clipsToBounds=YES;
camView.center = CGPointMake(self.keyboard.barcodeView.frame.size.width/2,self.keyboard.barcodeView.frame.size.height/2);
[self.keyboard.barcodeView addSubview:camView];
如果我在我的键盘上按一个特殊的键,这个叫做:
-(void)scanBarcodeNow{
AudioServicesPlaySystemSound(systemSoundTock);
NSLog(@"Start scanning...");
self.keyboard.barcodeView.hidden=false;
[self.keyboard.barcodeView addSubview:camView];
[self.keyboard.barcodeView setBackgroundColor:[UIColor redColor]];
[self.captureSession startRunning];
}
唯一的事情是,keyboard.barcodeView将其背景颜色更改为红色.我已经看到,我所做的所有接线应该是好的.但是没有显示凸轮的视频….
谁能帮我吗?
解决方法
您要恢复为空的原因是因为您无法访问它.这其实不是一个bug.根据苹果指南,某些API不适用于iOS 8扩展(请参阅下面的第3项).
它吸吮,但我总是鼓励人们阅读新的功能,看看他们想做什么是可能的,在住在一个想法(节省很多时间)之前.肯定查看App Extension Programming Guide了解更多信息.