-
Notifications
You must be signed in to change notification settings - Fork 12
Working with card reader
Aside from signing documents with ID card, you can use MoppLib to read data from ID card.
You don't need to worry about handling connections with card reader. MoppLib will do that for you. Whenever you call a method, that needs interaction with card reader, MoppLib will check if it is connected to card reader. When no reader is connected, it will ask user to connect it.
ACR3901U-S1 Secure Bluetooth® Contact Card Reader
Although MoppLib does most of the work for you, you sometimes might want to check if card reader is already connected.
BOOL isConnected = [MoppLibCardActions isReaderConnected]
When reader is connected, you may also want to know if card is inserted properly in card reader, to provide more information to your user.
[MoppLibCardActions isCardInserted:^(BOOL isInserted) {
NSString *result = isInserted ? @"Card is inserted" : @"Card is not found";
NSLog(@"%@", result);
}];
MoppLib can also send you notifications when card status changes. To get notifications, add observer for kMoppLibNotificationReaderStatusChanged
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cardStatusChanged) name:kMoppLibNotificationReaderStatusChanged object:nil];
}
- (void)cardStatusChanged {
BOOL isReaderConnected = [MoppLibCardActions isReaderConnected];
[MoppLibCardActions isCardInserted:^(BOOL isInserted) {
// Card status updated
}];
}
You can get some data from ID card, that is publicly available. This includes things like card owner name, birth date, document number etc.
[MoppLibCardActions cardPersonalDataWithViewController:self success:^(MoppLibPersonalData *personalData) {
NSLog(@"First name line 1: %@", personalData.firstNameLine1);
NSLog(@"First name line 2: %@", personalData.firstNameLine2);
NSLog(@"Surname: %@", personalData.surname);
NSLog(@"Expiry: %@", personalData.expiryDate);
NSLog(@"Document number: %@", personalData.documentNumber);
NSLog(@"Personal identification code: %@", personalData.personalIdentificationCode);
NSLog(@"Birth date: %@", personalData.birthDate);
NSLog(@"Nationality: %@", personalData.nationality);
NSLog(@"Sex: %@", personalData.sex);
NSLog(@"Date issued: %@", personalData.dateIssued);
NSLog(@"Permit type: %@", personalData.residentPermitType);
NSLog(@"Notes 1: %@", personalData.notes1);
NSLog(@"Notes 2: %@", personalData.notes2);
NSLog(@"Notes 3: %@", personalData.notes3);
NSLog(@"Notes 4: %@", personalData.notes4);
} failure:^(NSError *error) {
NSLog(@"Failed to get personal data: %@", error);
}];
Reading data from card can be time-consuming. If you don't need all available data, then you can choose to get only the set of most important values.
[MoppLibCardActions minimalCardPersonalDataWithViewController:self success:^(MoppLibPersonalData *personalData) {
NSLog(@"First name line 1: %@", personalData.firstNameLine1);
NSLog(@"First name line 2: %@", personalData.firstNameLine2);
NSLog(@"Surname: %@", personalData.surname);
NSLog(@"Expiry: %@", personalData.expiryDate);
NSLog(@"Document number: %@", personalData.documentNumber);
NSLog(@"Personal identification code: %@", personalData.personalIdentificationCode);
NSLog(@"Birth date: %@", personalData.birthDate);
NSLog(@"Nationality: %@", personalData.nationality);
} failure:^(NSError *error) {
NSLog(@"Failed to get personal data: %@", error);
}];
There are two certificates on ID card - authentication and signing certificate. You can get some basic data like expiry dates from them.
For signing certificate use
[MoppLibCardActions signingCertWithViewController:self success:^(MoppLibCertData *data) {
NSLog(@"Is valid: %d", data.isValid);
NSLog(@"Expiry date: %@", data.expiryDate);
NSLog(@"Usage count: %i", data.usageCount);
} failure:^(NSError *error) {
NSLog(@"Failed to get cert: %@", error);
}];
For authentication certificate use
[MoppLibCardActions authenticationCertWithViewController success:^(MoppLibCertData *data) {
NSLog(@"Is valid: %d", data.isValid);
NSLog(@"Expiry date: %@", data.expiryDate);
NSLog(@"Usage count: %i", data.usageCount);
NSLog(@"Email: %@", data.email);
} failure:^(NSError *error) {
NSLog(@"Failed to get cert: %@", error);
}];
PIN and PUK codes can get blocked when invalid code is used for some actions. It is important to notify user in that case, so they would know when they have to take action in order to unblock blocked code. It is not possible to continue to use certain functionality, like document signing, when PIN is blocked.
MoppLib provides methods for getting retry counter value from ID card. The number returned represents how many retries user has left for each code. When count reaches 0, then that particular code is blocked and can't be used anymore until user unblocks it. Unblock actions are not available for third-party applications. User will have to use one of RIA DigiDoc applications to unblock.
[MoppLibCardActions pukRetryCountWithViewController:self success:^(NSNumber *count) {
NSLog(@"PUK retry count: %@", count);
} failure:^(NSError *error) {
NSLog(@"Failed to get PUK retry count: %@", error);
}];
[MoppLibCardActions pin1RetryCountWithViewController:self success:^(NSNumber *count) {
NSLog(@"PIN1 retry count: %@", count);
} failure:^(NSError *error) {
NSLog(@"Failed to get PIN1 retry count: %@", error);
}];
[MoppLibCardActions pin2RetryCountWithViewController:self success:^(NSNumber *count) {
NSLog(@"PIN2 retry count: %@", count);
} failure:^(NSError *error) {
NSLog(@"Failed to get PIN2 retry count: %@", error);
}];
MoppLib can also send you notifications when retry counter changes. To get notifications, add observer for kMoppLibNotificationRetryCounterChanged
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(retryCounterChanged) name:kMoppLibNotificationRetryCounterChanged object:nil];
}
- (void)retryCounterChanged {
[MoppLibCardActions pin1RetryCountWithViewController:self success:^(NSNumber *count) {
NSLog(@"PIN1 counter changed to %@", count);
} failure:^(NSError *error) {
NSLog(@"Error %@", error);
}];
[MoppLibCardActions pin2RetryCountWithViewController:self success:^(NSNumber *count) {
NSLog(@"PIN2 counter changed to %@", count);
} failure:^(NSError *error) {
NSLog(@"Error %@", error);
}];
[MoppLibCardActions pukRetryCountWithViewController:self success:^(NSNumber *count) {
NSLog(@"PUK counter changed to %@", count);
} failure:^(NSError *error) {
NSLog(@"Error %@", error);
}];
}