SBSDKScannerViewControllerDelegate
@protocol SBSDKScannerViewControllerDelegate <NSObject>
A delegate protocol to customize the behavior, look and feel of the SBSDKScannerViewController.
-
Asks the delegate whether to detect on the next video frame or not. Return NO if you don’t want detection on video frames, e.g. when a view controller is presented modally or when your view controller’s view currently is not in the view hierarchy.
Declaration
Objective-C
- (BOOL)scannerControllerShouldAnalyseVideoFrame: (nonnull SBSDKScannerViewController *)controller;
Swift
optional func scannerControllerShouldAnalyseVideoFrame(_ controller: SBSDKScannerViewController) -> Bool
Parameters
controller
The calling SBSDKScannerViewController.
Return Value
YES if the video frame should be analyzed, NO otherwise.
-
Informs the delegate that the scanner has processed a video frame.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didSampleVideoFrame:(nonnull UIImage *)videoFrameImage detectionResult:(nonnull SBSDKDocumentDetectorResult *)result;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didSampleVideoFrame videoFrameImage: UIImage, detectionResult result: SBSDKDocumentDetectorResult)
Parameters
controller
The calling SBSDKScannerViewController.
videoFrameImage
An UIImage with the contents of the video frame.
result
The result of the document detection done on this video frame.
-
Informs the delegate that the scanner has sampled a video frame. Use this method to do custom processing on live video frames.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didSampleVideoFrame:(nonnull UIImage *)videoFrameImage;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didSampleVideoFrame videoFrameImage: UIImage)
Parameters
controller
The calling SBSDKScannerViewController.
videoFrameImage
An UIImage with the contents of the video frame.
-
Informs the delegate that the scanner has toggled automatic shutter release on or off.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didToggleAutoShutter:(BOOL)enable;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didToggleAutoShutter enable: Bool)
Parameters
controller
The calling SBSDKScannerViewController.
enable
YES, if the auto shutter was turned on, NO otherwise.
-
Tells the delegate that a still image is about to be captured. Here you can change the appearance of you custom shutter button or HUD to reflect in the UI that we are now busy taking an image.
Declaration
Objective-C
- (void)scannerControllerWillCaptureStillImage: (nonnull SBSDKScannerViewController *)controller;
Swift
optional func scannerControllerWillCaptureStillImage(_ controller: SBSDKScannerViewController)
Parameters
controller
The calling SBSDKScannerViewController.
-
- Asks the delegate whether to automatically crop the document image or not, depending on the current shutter mode and
- how the shutter was released: manually or automatically.
Declaration
Objective-C
- (BOOL)scannerController:(nonnull SBSDKScannerViewController *)controller shouldAutocropCapturedImageWithMode:(SBSDKShutterMode)mode manualShutter:(BOOL)manual;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, shouldAutocropCapturedImageWith mode: SBSDKShutterMode, manualShutter manual: Bool) -> Bool
Parameters
controller
The calling SBSDKScannerViewController.
mode
The shutter mode of the SBSDKScannerViewController at the time the image has been captured.
manual
Whether the shutter was releases automatically or manually.
Return Value
YES, if the detected polygon should be applied to the captured document image, NO otherwise.
-
Tells the delegate that a document image has been cropped out of an orientation corrected still image.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didCaptureDocumentImage:(nonnull UIImage *)documentImage;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didCaptureDocumentImage documentImage: UIImage)
Parameters
controller
The calling SBSDKScannerViewController.
documentImage
The cropped and perspective corrected documents image, rotated depending on the device orientation.
-
Tells the delegate that a still image has been captured and its orientation has been corrected. Optional.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didCaptureImage:(nonnull UIImage *)image;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didCapture image: UIImage)
Parameters
controller
The calling SBSDKScannerViewController.
image
The captured original image, rotated depending on the device orientation.
-
Tells the delegate that a still image has been captured and its orientation has been corrected. Optional.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didCaptureImage:(nonnull UIImage *)image withCaptureInfo:(nonnull SBSDKCaptureInfo *)info;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didCapture image: UIImage, with info: SBSDKCaptureInfo)
Parameters
controller
The calling SBSDKScannerViewController.
image
The captured original image, rotated depending on the device orientation.
info
Metadata of the capturing.
-
Tells the delegate that a still image has been captured and its orientation has been corrected. Optional.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didCaptureImage:(nullable UIImage *)image withDetectedPolygon:(nullable SBSDKPolygon *)polygon lensCameraProperties:(nullable SBSDKLensCameraProperties *)properties;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didCapture image: UIImage?, withDetectedPolygon polygon: SBSDKPolygon?, lensCameraProperties properties: SBSDKLensCameraProperties?)
Parameters
controller
The calling SBSDKScannerViewController.
image
The captured original image, rotated depending on the device orientation.
polygon
The polygon that was detected on the image.
properties
The properties of the camera and lens. Useful to calculate the aspect ratio of the cropped image.
-
Tells the delegate that a still image has been captured and its orientation has been corrected. Optional.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didCaptureImage:(nullable UIImage *)image withDetectedPolygon:(nullable SBSDKPolygon *)polygon imageMetadata:(nullable SBSDKImageMetadata *)metadata;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didCapture image: UIImage?, withDetectedPolygon polygon: SBSDKPolygon?, imageMetadata metadata: SBSDKImageMetadata?)
Parameters
controller
The calling SBSDKScannerViewController.
image
The captured original image, rotated depending on the device orientation.
polygon
The polygon that was detected on the image.
metadata
The images metadata object (EXIF, JFIF, TIFF etc).
-
Tells the delegate that capturing a still image has been failed The underlying error is provided. Optional.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didFailCapturingImage:(nonnull NSError *)error;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didFailCapturingImage error: Error)
Parameters
controller
The calling SBSDKScannerViewController.
error
The reason for the failure.
-
Tells the delegate that a document detection has been occurred on the current video frame. Optional. Here you can update your custom shutter button if needed and your HUD data.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didDetectPolygon:(nullable SBSDKPolygon *)polygon withStatus:(SBSDKDocumentDetectionStatus)status;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didDetect polygon: SBSDKPolygon?, with status: SBSDKDocumentDetectionStatus)
Parameters
controller
The calling SBSDKScannerViewController.
polygon
The polygon data describing where in the image the document was detected if any. Otherwise nil.
status
The status of the detection.
-
Asks the delegate if an automatic capture should be scheduled. Optional.
Declaration
Objective-C
- (BOOL)scannerController:(nonnull SBSDKScannerViewController *)controller shouldAutoCaptureWithPolygon:(nullable SBSDKPolygon *)polygon andStatus:(SBSDKDocumentDetectionStatus)status;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, shouldAutoCaptureWith polygon: SBSDKPolygon?, andStatus status: SBSDKDocumentDetectionStatus) -> Bool
Parameters
controller
The calling SBSDKScannerViewController.
polygon
The polygon data describing where in the image the document was detected if any. Otherwise nil.
status
The status of the detection.
-
Asks the delegate for a view to visualize the current detection status. Optional.
Declaration
Objective-C
- (nullable UIView *)scannerController: (nonnull SBSDKScannerViewController *)controller viewForDetectionStatus:(SBSDKDocumentDetectionStatus)status;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, viewFor status: SBSDKDocumentDetectionStatus) -> UIView?
Parameters
status
The status of the detection.
controller
The calling SBSDKScannerViewController.
Return Value
Your custom view to visualize the detection status, e.g. a label with localized text or an image view with an icon. If you return nil the standard label is displayed. If you want to show nothing just return an empty view ([UIView new]). If possible reuse the views per status or just use one single configurable view. The scanner view controller takes care of adding and removing your view from/to the view hierarchy.
-
Asks the delegate for the text to display for current detection status. Optional. Not called if custom status detection views are used. If not implemented english standard strings are applied. Return a string depending on the detection status, also consider the controllers autoShutterEnabled property.
Declaration
Objective-C
- (nullable NSString *)scannerController: (nonnull SBSDKScannerViewController *)controller localizedTextForDetectionStatus:(SBSDKDocumentDetectionStatus)status;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, localizedTextFor status: SBSDKDocumentDetectionStatus) -> String?
Parameters
controller
The calling SBSDKScannerViewController.
status
The status of the detection.
Return Value
The localized string to display on the status detection label or view. If you return nil the status view is hidden.
-
Asks the delegate for custom shutter release button. Optional.
Declaration
Objective-C
- (nullable UIButton *)scannerControllerCustomShutterButton: (nonnull SBSDKScannerViewController *)controller;
Swift
optional func scannerControllerCustomShutterButton(_ controller: SBSDKScannerViewController) -> UIButton?
Parameters
controller
The calling SBSDKScannerViewController.
Return Value
An instance of your custom shutter release button. Target and action are set automatically by controller. If you return nil, the built-in standard button is used.
-
Asks the delegate for shutter release buttons scale factor. Optional.
Declaration
Objective-C
- (CGFloat)scannerControllerScaleForShutterButton: (nonnull SBSDKScannerViewController *)controller;
Swift
optional func scannerControllerScale(forShutterButton controller: SBSDKScannerViewController) -> CGFloat
Parameters
controller
The calling SBSDKScannerViewController.
Return Value
A factor by which the shutter button is scaled. Defaults to 1.0.
-
Asks the delegate for shutter release buttons position in its superview. Optional.
Declaration
Objective-C
- (CGPoint)scannerControllerCenterForShutterButton: (nonnull SBSDKScannerViewController *)controller;
Swift
optional func scannerControllerCenter(forShutterButton controller: SBSDKScannerViewController) -> CGPoint
Parameters
controller
The calling SBSDKScannerViewController.
Return Value
A CGPoint defining the center position of the shutter button.
-
Asks the delegate on which view to place the shutter button.
Declaration
Objective-C
- (nonnull UIView *)scannerControllerSuperViewForShutterButton: (nonnull SBSDKScannerViewController *)controller;
Swift
optional func scannerControllerSuperView(forShutterButton controller: SBSDKScannerViewController) -> UIView
Return Value
A view in the current view hierarchy.
-
Implement this method to customize the detected documents polygon drawing. If you implement this method you are responsible for correct configuration of the shape layer and setting the shape layers path property. Implementing this method also disables calling of the delegate method -(UIColor *)scannerController:polygonColorForDetectionStatus:
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller drawPolygonPoints:(nonnull NSArray<NSValue *> *)pointValues withDetectionStatus:(SBSDKDocumentDetectionStatus)detectionStatus onLayer:(nonnull CAShapeLayer *)layer;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, drawPolygonPoints pointValues: [NSValue], with detectionStatus: SBSDKDocumentDetectionStatus, on layer: CAShapeLayer)
Parameters
controller
The calling SBSDKScannerViewController.
pointValues
NSArray of 4 NSValues, containing CGPointValues. Or nil if there was no polygon detected. Extract each point: CGPoint point = [pointValues[index] CGPointValue]. The points are already converted to layer coordinate system and therefore can directly be used for drawing or creating a bezier path.
detectionStatus
The current detection status.
layer
The shape layer that draws the bezier path of the polygon points. You can configure the layers stroke and fill color, the line width and other parameters. See the documentation for CAShapeLayer.
-
Asks the delegate for a color to use for displaying the detected documents polygon. Optional. Note: This method is not called if the delegate implements -(void)scannerController:drawPolygonPoints:withDetectionStatus:onLayer:
Declaration
Objective-C
- (nonnull UIColor *)scannerController: (nonnull SBSDKScannerViewController *)controller polygonColorForDetectionStatus:(SBSDKDocumentDetectionStatus)status;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, polygonColorFor status: SBSDKDocumentDetectionStatus) -> UIColor
Parameters
status
The status of the detection.
controller
The calling SBSDKScannerViewController.
Return Value
An UIColor representing the state of detections. You could for example return green for DetectionStateOK and red otherwise.
-
Asks the delegate for a color to use for displaying the detected documents polygon background. Optional. Note: This method is not called if the delegate implements -(void)scannerController:drawPolygonPoints:withDetectionStatus:onLayer:
Declaration
Objective-C
- (nonnull UIColor *)scannerController: (nonnull SBSDKScannerViewController *)controller backgroundPolygonColorForDetectionStatus: (SBSDKDocumentDetectionStatus)status;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, backgroundPolygonColorFor status: SBSDKDocumentDetectionStatus) -> UIColor
Parameters
status
The status of the detection.
controller
The calling SBSDKScannerViewController.
Return Value
An UIColor representing the state of detections. You could for example return green for DetectionStateOK and red otherwise.
-
Informs the delegate that the device orientation has changed. The SBSDKScannerController will use this orientation to rotate captured images. Optional.
Declaration
Objective-C
- (void) scannerControllerDidChangeDeviceOrientation: (nonnull SBSDKScannerViewController *)controller to:(UIDeviceOrientation)orientation transform:(CGAffineTransform)transform;
Swift
optional func scannerControllerDidChangeDeviceOrientation(_ controller: SBSDKScannerViewController, to orientation: UIDeviceOrientation, transform: CGAffineTransform)
Parameters
controller
The calling SBSDKScannerViewController.
orientation
The new device orientation used to rotate captured images automatically.
transform
The CGAffineTransform that can be used to rotate UI elements to reflect the current capture orientation.
-
Asks the delegate whether the camera UI, shutter button and guidance UI, should be rotated to reflect the device orientation or not.
Not called if the imageOrientationLock property is other than SBSDKOrientationLockNone.
Optional.
Declaration
Objective-C
- (BOOL)scannerController:(nonnull SBSDKScannerViewController *)controller shouldRotateInterfaceForDeviceOrientation:(UIDeviceOrientation)orientation transform:(CGAffineTransform)transform;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, shouldRotateInterfaceFor orientation: UIDeviceOrientation, transform: CGAffineTransform) -> Bool
Parameters
controller
The calling SBSDKScannerViewController.
orientation
The new device orientation the device is rotated to.
transform
The CGAffineTransform that will be used to rotate UI elements.
-
Asks the delegate if the receiver should detect QR- and bar codes. Optional.
Declaration
Objective-C
- (BOOL)scannerControllerShouldDetectMachineReadableCodes: (nonnull SBSDKScannerViewController *)controller;
Swift
optional func scannerControllerShouldDetectMachineReadableCodes(_ controller: SBSDKScannerViewController) -> Bool
Parameters
controller
The calling SBSDKScannerViewController.
-
Informs the delegate that the receiver has detected a QR code. Optional.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didDetectMachineReadableCodes: (nonnull NSArray<SBSDKBarcodeScannerResult *> *)codes;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didDetectMachineReadableCodes codes: [SBSDKBarcodeScannerResult])
Parameters
controller
The calling SBSDKScannerViewController.
codes
Array of SBSDKBarcodeScannerResult containing the detected machine readable code metadata.
-
Returns captured barcode image. Will fire only if
barcodeImageGenerationType
parameter is notSBSDKBarcodeImageGenerationTypeNone
. Optional.Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didCaptureBarcodeImage:(nonnull UIImage *)barcodeImage;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didCaptureBarcodeImage barcodeImage: UIImage)
Parameters
controller
The calling SBSDKScannerViewController.
barcodeImage
A captured device-orientation-corrected barcode image.
-
Informs the delegate that the receiver did change the rect of the view finder.
Declaration
Objective-C
- (void)scannerController:(nonnull SBSDKScannerViewController *)controller didChangeViewFinderRect:(CGRect)rect;
Swift
optional func scannerController(_ controller: SBSDKScannerViewController, didChangeViewFinderRect rect: CGRect)
Parameters
controller
The calling SBSDKScannerViewController.
rect
The new rectangle of the view finder in the controllers view space. Equals to CGRectZero when the view finder is not visible.