Disconnecting Readers
In disconnected readers it is likely that the appropriate reader events should be subscribed to. It is best practice to assert that a reader is connected before proceeding so users aren't confused by erroneous messages.
With an audio jack reader:
if ( CardReaderController.isCardReaderConnected() && CardReaderController.getConnectedReader().getConnectionMethod() == CardReader.ConnectionMethod.AUDIO )
{
// instruct user to physically disconnect device
}
else
{
// indicate no audio device detected
}
- (IBAction)disconnectReader:(id)sender {
[[ANPCardReaderController sharedController] subscribeOnCardReaderError:^(ANPMeaningfulError * _Nullable error) {
NSLog(@"OnCardReaderError --> %@", error);
[self appendText:[NSString stringWithFormat:@"\n\nOnCardReaderError %@", error.message]];
}];
[[ANPCardReaderController sharedController] subscribeOnCardReaderDisConnected:^{
NSLog(@"OnCardReaderDisConnected");
[self appendText:@"\n\n OnCardReaderDisConnected"];
}];
[[ANPCardReaderController sharedController] disconnectReader];
}
With a bluetooth reader:
if ( CardReaderController.isCardReaderConnected() && cardReader.getConnectionMethod() == CardReader.ConnectionMethod.BLUETOOTH)
{
// indicate bluetooth disconnection in progress
cardReaderController.disconnectReader();
}
else
{
// indicate no bluetooth reader connected
}
- (IBAction)disconnectReader:(id)sender {
[[ANPCardReaderController sharedController] subscribeOnCardReaderError:^(ANPMeaningfulError * _Nullable error) {
NSLog(@"OnCardReaderError --> %@", error);
[self appendText:[NSString stringWithFormat:@"\n\nOnCardReaderError %@", error.message]];
}];
[[ANPCardReaderController sharedController] subscribeOnCardReaderDisConnected:^{
NSLog(@"OnCardReaderDisConnected");
[self appendText:@"\n\n OnCardReaderDisConnected"];
}];
[[ANPCardReaderController sharedController] disconnectReader];
}
Updated over 5 years ago