2014-09-21 4 views
9

바코드 스캐너의 역할을하는 맞춤 키보드를 만들고 싶습니다. 이미 전체 코딩을했는데 예상대로 출력되지 않습니다. 카메라 권한 (처음)을 요청 받았지만 카메라가보기에 비디오를 보내지 않습니다.iOS 맞춤 키보드 - 카메라가 작동하지 않습니다.

안전을 이유로 키보드를 사용하는 데 몇 가지 제한이있을 수 있습니다.) 스캔) 바코드 (의 viewDidLoad의 일부를

Error: (null) 
flash turned on -> OK 

2 :

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"); 
     } 
    } 

} 

이 나에게이 로그 출력을 제공 켭니다,하지만 아무것도 플래시를 사용하여 발생하지 않습니다 내 키보드의 특수 키를 누르면

// 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가 빨간색으로 배경색을 변경하는 것입니다. 나는 내가 한 배선이 모두 OK 여야한다는 것을 보았습니다. 그러나 캠에서 비디오가 표시되지 않습니다 ....

아무도 도와 줄 수 있습니까?

+0

이 키보드를 만드는 데 어떤 진전이 있었습니까? 나는 같은 것을 만들고 싶었다. –

답변

18

null로 돌아가는 이유는 액세스 권한이 없기 때문입니다. 실제로는 버그가 아닙니다. Apple 지침에 따르면 iOS 8 확장에는 특정 API를 사용할 수 없습니다 (아래 글 머리 기호 3 참조).

enter image description here

이 짜증,하지만 난 항상 새로운 기능을 읽을과 그들이하고 싶은 것은 아이디어에 거주하기 전에, 가능하다 (많은 시간을 저장합니다) 있는지 확인하기 위해 사람들을 격려한다. 자세한 내용은 App Extension Programming Guide을 확인하십시오.

관련 문제