2017-01-12 97 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; 
}]; 
相關問題