2017-01-12 9 views
0

私はMTBBarcodeScannerinterfaceを使用してバーコードスキャナアプリケーションを実装しています。
私は私のコードでスキャナの静止画像を取得する必要があるので、私は関数を呼び出すしようとしています:IOSに呼び出しエラーが発生する関数

- (void)captureStillImage:(void (^)(UIImage *image, NSError *error))captureBlock { 

    if ([self isCapturingStillImage]) { 
     if (captureBlock) { 
      NSError *error = [NSError errorWithDomain:kErrorDomain 
               code:kErrorCodeStillImageCaptureInProgress 
              userInfo:@{NSLocalizedDescriptionKey : @"Still image capture is already in progress. Check with isCapturingStillImage"}]; 
      captureBlock(nil, error); 
     } 
     return; 
    } 

    AVCaptureConnection *stillConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo]; 

    if (stillConnection == nil) { 
     if (captureBlock) { 
      NSError *error = [NSError errorWithDomain:kErrorDomain 
               code:kErrorCodeSessionIsClosed 
              userInfo:@{NSLocalizedDescriptionKey : @"AVCaptureConnection is closed"}]; 
      captureBlock(nil, error); 
     } 
     return; 
    } 

    [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:stillConnection 
                 completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { 
                  if (error) { 
                   captureBlock(nil, error); 
                   return; 
                  } 

                  NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; 
                  UIImage *image = [UIImage imageWithData:jpegData]; 
                  if (captureBlock) { 
                   captureBlock(image, nil); 
                  } 

                 }]; 

} 

私のViewControllerから、私は次のようにこの関数を呼び出しています:

UIImage *img; 
NSError *e; 
[_scanner captureStillImage:img :e]; 

が、

No visible @interface for 'MTBBarcodeScanner' declares the selector 'captureStillImage::

どのように私は、この関数が私のUIViewcontrollerサブクラス呼び出すことができます。私にエラーを与えて?

答えて

1

ブロックの構文が正しくありません。それは次のようになります。

[_scanner captureStillImage:^(UIImage *image, NSError *error) { 

}]; 

はまた、これはコールバック関数である、あなたがそれにパラメータを供給することになっていない、これらは、それから返されています。

コールバック関数以外のコールバック関数の戻り値を表す変数をコールバックに含めるには、__block変数を宣言する必要があります。

__block UIImage* img; 
__block NSError* e; 

[_scanner captureStillImage:^(UIImage *image, NSError *error) { 
    img = image; 
    e = error; 
}]; 
関連する問題