Skip to content

How to initiate a scanning event

Set the Scanner Delegate

When a scanner starts connecting, set the delegate so you can receive barcodes as soon as they arrive (barcodes may arrive during discovery when the central is restoring).

To set the scanner delegate, confirm to the PGPeripheralDelegate protocol.

- (void)centralManager:(PGCentralManager *)centralManager connectingToScanner:(PGPeripheral *)scanner {
    scanner.delegate = self;
func centralManager(_ centralManager: PGCentralManager, connectingToScanner scanner: PGPeripheral) {
    scanner.delegate = self

Initiate a scan

When you scan a barcode, the delegate method is called and the PGScannedBarcodeResult object, containing the scan content and scan symbology, is retrieved:

- (void)peripheral:(nonnull PGPeripheral *)peripheral didScanBarcodeWithResult:(nonnull PGScannedBarcodeResult *)result {
  NSLog(@"Barcode scanned: %@", result.barcodeContent);
  if (result.barcodeSymbology){
    NSLog(@"Barcode symbology: %@", result.barcodeSymbology);
func peripheral(_ peripheral: PGPeripheral, didScanBarcodeWith data: PGScannedBarcodeResult) {
  print("Barcode scanned: \(data.barcodeContent)")
  if let symbology = data.barcodeSymbology {
    print("Barcode symbology: \(symbology)")