Skip to content

How to initiate connection

Create the Central Manager object

To set the delegate method to the central manager object, confirm PGCentralManagerDelegate.

#import <ConnectSDK/ConnectSDK.h>
...
- (void)setup {
    self.central = [[PGCentralManager alloc] initWithDelegate:self enableRestoration:NO];
}
import ConnectSDK
...
var central: PGCentralManager?
...
func setup() {
    central = PGCentralManager(delegate: self, enableRestoration: false)
}

Initiate new connections

When the state of the central is PGManagerStatePoweredOn, to initiate new connections, create a connection QR code:

- (void)managerDidUpdateState:(PGManager *)manager {
    if(manager.state == PGManagerStatePoweredOn) {
        CGFloat s = MIN(self.qrImageView.frame.size.width, self.qrImageView.frame.size.height);
        UIImage *im = [self.central initiateScannerConnectionWithImageSize: CGSizeMake(s, s)];
        self.qrImageView.image = im;
    }
}
func managerDidUpdateState(_ manager: PGManager) {
    if manager.state == .poweredOn {
        let s = min(qrImageView.frame.size.width, qrImageView.frame.size.height)
        let im = central.initiateScannerConnection(withImageSize: CGSize(width: s, height: s))
        qrImageView.image = im
    }
}

Connection state machine

The diagram below details the states during the scanner's connection process to the customer app.

Connection states