AccessoryModule Usage

The accessory module was added as a single place from where you are able to handle accessories independent of a transaction. In there you are able to connect, update and disconnect an accessory. In addition, you can access the accessory reference individually and access barcode and printing components.

In order to make full use of the accessory module, you should always set the optional keepAlive flag on the MPAccessoryParameters. This makes sure that the connection to the accessory is not closed after the transaction.

As part of a normal transaction, all the following three steps will be done implicitly. By manually managing the connections and updates, you will have more granular control over the workflow and can provide more flexibility to the merchant. Already connected accessories will be picked up automatically by the transaction workflow (given you provide the same accessory parameters).

Connecting to an Accessory

In order to connect to an accessory, you just provide your normal MPAccessoryParameters to the connect method.

- (void)connectToAccessory {
    
    MPAccessoryParameters *parameters = [MPAccessoryParameters externalAccessoryParametersWithFamily:MPAccessoryFamilyMiuraMPI protocol:@"com.miura.shuttle" optionals:^(id  _Nonnull optionals) {
        optionals.keepAlive = YES;
    }];
    
    MPAccessoryProcess *process = [self.transactionProvider.accessoryModule connectToAccessoryWithAccessoryParameters:parameters statusChanged:^(MPAccessoryProcess * _Nonnull accesoryProcess, MPAccessory * _Nullable accessory, MPAccessoryProcessDetails * _Nonnull details) {
        
        //status updates on the ongoing process
        
    } completed:^(MPAccessoryProcess * _Nonnull accesoryProcess, MPAccessory * _Nonnull accessory, MPAccessoryProcessDetails * _Nonnull details) {
        
        //connect finished, check the result for the outcome
        
    }];
}

Abort Connecting to an Accessory

A connect will automatically retry connecting to an accessory if it is not found. To exit out of this, use the requestAbort on the MPAccessoryProcess that is returned when starting the connect.

- (void)abortConnectToAccessory:(MPAccessoryProcess *)process {
    
    [process requestAbort];
    
}

Updating an Accessory

This step will check for any available updates for the reader and if available applies it directly.

- (void)checkAccessoryUpdate {
    
    MPAccessory *accessory = self.transactionProvider.accessoryModule.connectedAccesories[0];
    [self.transactionProvider.accessoryModule updateAccessory:accessory statusChanged:^(MPAccessoryProcess * _Nonnull accesoryProcess, MPAccessory * _Nullable accessory, MPAccessoryProcessDetails * _Nonnull details) {
        
        //status updates on the ongoing process
        
    } completed:^(MPAccessoryProcess * _Nonnull accesoryProcess, MPAccessory * _Nonnull accessory, MPAccessoryProcessDetails * _Nonnull details) {
        
        //update check (and update) finished, check the result for the outcome
        
    }];
}

Disconnecting from an Accessory

Disconnect from an accessory if it is not used in a while or when you want to use a different one.

- (void)disconnectAccessory {
    
    MPAccessory *accessory = self.transactionProvider.accessoryModule.connectedAccesories[0];
    [self.transactionProvider.accessoryModule disconnectFromAccessory:accessory statusChanged:^(MPAccessoryProcess * _Nonnull accesoryProcess, MPAccessory * _Nullable accessory, MPAccessoryProcessDetails * _Nonnull details) {
        
        //status updates on the ongoing process
        
    } completed:^(MPAccessoryProcess * _Nonnull accesoryProcess, MPAccessory * _Nonnull accessory, MPAccessoryProcessDetails * _Nonnull details) {
        
        //disconnect finished, check the result for the outcome
        
    }];
}


The accessory module was added as a single place from where you are able to handle accessories independent of a transaction. In there you are able to connect, update and disconnect an accessory. In addition, you can access the accessory reference individually and access barcode and printing components.

In order to make full use of the accessory module, you should always set the optional keepAlive flag on the AccessoryParameters. This makes sure that the connection to the accessory is not closed after the transaction.

As part of a normal transaction, all the following three steps will be done implicitly. By manually managing the connections and updates, you will have more granular control over the workflow and can provide more flexibility to the merchant. Already connected accessories will be picked up automatically by the transaction workflow (given you provide the same accessory parameters).

Connecting to an Accessory

In order to connect to an accessory, you just provide your normal MPAccessoryParameters to the connect method.

private void connectToAccessory() {
    AccessoryParameters accessoryParameters = new AccessoryParameters.Builder(AccessoryFamily.MIURA_MPI).bluetooth().keepAlive(true).build();
    AccessoryProcess connectProcess = transactionProvider.getAccessoryModule().connectToAccessory(accessoryParameters, new AccessoryConnectListener() {
        @Override
        public void onStatusChanged(AccessoryProcess accessoryProcess, Accessory accessory, AccessoryProcessDetails details) {
            // status updates on the ongoing process
        }

        @Override
        public void onCompleted(AccessoryProcess accessoryProcess, Accessory accessory, AccessoryProcessDetails details) {
            // connection finished, check the process details for the outcome
        }
    });
}

Abort Connecting to an Accessory

A connect will automatically retry connecting to an accessory if it is not found. To exit out of this, use the requestAbort on the MPAccessoryProcess that is returned when starting the connect.

private void abortConnectToAccessory(AccessoryProcess connectProcess) {
    connectProcess.requestAbort();
}

Updating an Accessory

This step will check for any available updates for the reader and if available applies it directly.

private void updateAccessory() {
    Accessory accessory = transactionProvider.getAccessoryModule().getConnectedAccessories().get(0);
    AccessoryProcess updateProcess = transactionProvider.getAccessoryModule().updateAccessory(accessory, new AccessoryUpdateListener() {
        @Override
        public void onStatusChanged(AccessoryProcess accessoryProcess, Accessory accessory, AccessoryProcessDetails details) {
            // status updates on the ongoing process
        }

        @Override
        public void onCompleted(AccessoryProcess accessoryProcess, Accessory accessory, AccessoryProcessDetails details) {
            // update check (and update) finished,, check the process details for the outcome
        }
    });
}

Disconnecting from an Accessory

Disconnect from an accessory if it is not used in a while or when you want to use a different one.

private void disconnectFromAccessory() {
    Accessory accessory = transactionProvider.getAccessoryModule().getConnectedAccessories().get(0);
    AccessoryProcess disconnectProcess = transactionProvider.getAccessoryModule().disconnectFromAccessory(mConnectedAccessory, new AccessoryDisconnectListener2() {
        @Override
        public void onStatusChanged(AccessoryProcess process, Accessory model, AccessoryProcessDetails processDetails) {
            // status updates on the ongoing process
        }

        @Override
        public void onCompleted(AccessoryProcess process, Accessory model, AccessoryProcessDetails processDetails) {
            // disconnection finished, check the process details for the outcome
        }
    });
}