Connection Keep-Alive

With Connection Keep-Alive you have the option to keep the connection to the card reader established after the first transaction has been completed. Subsequent transactions will make use of the already connected reader, allowing your merchants to take card payments even faster.

The Connection Keep-Alive feature is designed for setups where the card reader is connected to a power source most of the time. If your merchant wants to run the card reader mostly on battery power, you need to implement some basic power management using the explicit disconnect method documented below.

Enabling Connection Keep-Alive

Just set keepAlive to YES in the MPAccessoryParameters you supply:

[MPAccessoryParameters externalAccessoryParametersWithFamily:MPAccessoryFamilyMiuraMPI protocol:@"com.miura.shuttle" optionals:^(id optionals) {

            [optionals setKeepAlive:YES]; 
        }];

Once the first transaction has been finished, you will notice that the card reader remains connected and displays the idle screen. If you now use the same MPAccessoryParameters for subsequent transactions, the already connected reader will be used.

From SDK Version 2.19 onwards, you can also customize the idle screen text shown on the reader through the MPAccessoryParameters.

Note that each connection to the reader is tied to an instance of the MPTransactionProvider. In order to use the Connection Keep-Alive feature, you have to create a single instance of MPTransactionProvider once during application startup and use that instance for interacting with the SDK throughout the application.

Disconnecting from the Card Reader

Through the MPAccessoryModule in the MPTransactionProvider you can disconnect from a connected reader explicitly. This is especially useful when you are running the card reader on battery power and want to disconnect after a certain idle time or situtation (e.g. merchants logs out of the POS system).

MPAccessoryModule *accessoryModule = transactionProvider.accessoryModule;

    MPAccessory *accessory = [[accessoryModule connectedAccesories] firstObject];

    [accessoryModule disconnectFromAccessory:accessory statusChanged:^(MPAccessoryProcess *accesoryProcess, MPAccessory *accessory, MPAccessoryProcessDetails *details) {

         // status updates on the disconnect process

    } completed:^(MPAccessoryProcess *accesoryProcess, MPAccessory *accessory, MPAccessoryProcessDetails *details) {

        if (details.state == MPAccessoryProcessDetailsStateFailed) {

            NSLog(@"Disconnect failed with error: %@", details.error);
        } else {

            NSLog(@"Disconnect success");
        }
    }];


With Connection Keep-Alive you have the option to keep the connection to the card reader established after the first transaction has been completed. Subsequent transactions will make use of the already connected reader, allowing your merchants to take card payments even faster.

The Connection Keep-Alive feature is designed for setups where the card reader is connected to a power source most of the time. If your merchant wants to run the card reader mostly on battery power, you need to implement some basic power management using the explicit disconnect method documented below.

Enabling Connection Keep-Alive

Just set keepAlive(...) to true in the AccessoryParameters you supply:

AccessoryParameters params = new AccessoryParameters.Builder(AccessoryFamily.MIURA_MPI).
                bluetooth().
                keepAlive(true).
                build();

Once the first transaction has been finished, you will notice that the card reader remains connected and displays the idle screen. If you now use the same AccessoryParameters for subsequent transactions, the already connected reader will be used.

You can customize the idle screen text shown on the reader through the AccessoryParameters as well.

Note that each connection to the reader is tied to an instance of the TransactionProvider. In order to use the Connection Keep-Alive feature, you have to create a single instance of TransactionProvider once during application startup and use that instance for interacting with the SDK throughout the application.

Disconnecting from the Card Reader

Through the AccessoryModule in the TransactionProvider you can disconnect from a connected reader explicitly. This is especially useful when you are running the card reader on battery power and want to disconnect after a certain idle time or situtation (e.g. merchants logs out of the POS system).

AccessoryModule accessoryModule = transactionProvider.getAccessoryModule();
Accessory accessory = accessoryModule.getConnectedAccessories().get(0);

accessoryModule.disconnectFromAccessory(accessory, 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
         if (processDetais.getState() == AccessoryProcessDetails.FAILED) {
            Log.d(TAG, "disconnect failed: " + processDetais.getError());
        } else {
            Log.d(TAG, "disconnect success");
        }
    }
});

Can we help you?

If you cannot find your answer, contact us and we'll get in touch with you soon.

© Copyright 2017 Payworks GmbH. Legal.