iOS8:自定义键盘 - 在键盘背景下用AVCaptureVideoPreviewLayer打开相机

时间:2014-10-15 19:17:14

标签: ios keyboard ios8 ios8-extension

可以在iOS8自定义键盘的后台打开AVCaptureVideoPreviewLayer吗? 我尝试使用此代码

    AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (videoDevice)
{
    NSError *error;
    AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
    if (!error)
    {
        if ([session canAddInput:videoInput])
        {
            [session addInput:videoInput];
            AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
            previewLayer.frame = self.bounds;
            NSLog(@"open %@",NSStringFromCGRect(self.bounds));
            [self.camView.layer addSublayer:previewLayer];
            [session startRunning];
        }
    }
}

在键盘的背景中请求使用照相机但不打开照相机的许可。 请帮我。 感谢。

0 个答案:

没有答案
相关问题