Managing containers - siimsuu1/MOPP-iOS GitHub Wiki
Before you can sign documents, you need to add them to a container.
Use createContainer method.
Make sure you include container name and .bdoc or .asice extension in container path.
NSString *containerPath = @"path/to/container.bdoc";
NSString *filePaths = @[@"path/to/file"];
MoppLibContainerActions *sharedInstance = [MoppLibContainerActions sharedInstance];
[sharedInstance createContainerWithPath:containerPath withDataFilePaths:filePaths success:^(MoppLibContainer *container) {
NSLog(@"Container created");
} failure:^(NSError *error) {
NSLog(@"Failed to create container: %@", error);
}];
Files can be added to existing container or removed, but only if container has not been signed by anyone yet.
To add files to container use addDataFilesToContainer method:
NSString *containerPath = @"path/to/container.bdoc";
NSString *filePaths = @[@"path/to/file"];
MoppLibContainerActions *sharedInstance = [MoppLibContainerActions sharedInstance];
[sharedInstance addDataFilesToContainerWithPath:containerPath withDataFilePaths:filePaths success:^(MoppLibContainer *container) {
NSLog(@"Files added");
} failure:^(NSError *error) {
NSLog(@"Failed to add files: %@", error);
}];
To remove files from container use removeDataFileFromContainer method:
NSString *containerPath = @"path/to/container.bdoc";
MoppLibContainerActions *sharedInstance = [MoppLibContainerActions sharedInstance];
[sharedInstance removeDataFileFromContainerWithPath:containerPath atIndex:1 success:^(MoppLibContainer *container) {
NSLog(@"File removed");
} failure:^(NSError *error) {
NSLog(@"Failed to remove file: %@", error);
}];
Signatures can be added to containers only. Add all documents to container before signing it. Additional files can't be added to already signed container. If you still need to add files to signed container, you need to remove all signatures from it first and have all parties sign updated container again.
There are two options for signing - with Mobile-ID or with physical ID-card. You should let user choose between those two methods. MoppLib has separate methods for both cases.
For signing with physical ID-card, user must have a card reader, that they can connect to their device.
MoppLib currently supports two card readers:
In order to add a signature to the container with ID-card or acquiring ID-card information you must first start discovering supported card readers by using startDiscoveringReaders method.
When finished working with ID-card related functionality, stopDiscoveringReaders method should be called.
Implement MoppLibCardReaderManagerDelegate protocol to receive status about the card reader state.
Set the delegate by calling MoppLibCardReaderManager's method setDelegate:
[[MoppLibCardReaderManager sharedInstance] setDelegate:self];
where 'self' being the object implementing MoppLibCardReaderManagerDelegate protocol
.
ID-card related methods can be used only when state CardConnected has been returned from moppLibCardReaderStatusDidChange method.
To add signature with ID-card, use addSignature method:
NSString *containerPath = @"path/to/container.bdoc";
MoppLibContainerActions *sharedInstance = [MoppLibContainerActions sharedInstance];
[sharedInstance addSignature:containerPath controller:self success:^(MoppLibContainer *container, BOOL signatureWasAdded) {
// Adding signature complete
} failure:^(NSError *error) {
NSLog(@"Failed to add signature: %@", error);
}];
For signing with Mobile-ID, you must provide some data about the person that is providing signature. Id code and phone number are required to verify, that SIM card is allowed to give signature.
To add signature with Mobile-ID use mobileCreateSignatureWithContainer method:
NSString *containerPath = @"path/to/container.bdoc";
NSString *number = @"+37255555555";
NSString *idCode = @"47101010033";
NSString *lang = @"EST";
MoppLibContainerActions *sharedInstance = [MoppLibContainerActions sharedInstance];
[sharedInstance mobileCreateSignatureWithContainer:containerPath idCode:idCode language:lang phoneNumber:number withCompletion:^(MoppLibMobileCreateSignatureResponse *response) {
// Request was completed. Response object contains challenge id, which you need to display on screen
} andStatus:^(MoppLibContainer *container, NSError *error, NSString *status) {
if (error.domain) {
// Failed with error
} else if (container) {
// Signature was obtained
} else {
// Status was updated
}
}];
MoppLib will first make a request to get challenge id for you. Once it succeeds, completion block is called. You need to display challenge id in your application, so user can verify, that signature is given with correct device.
Obtaining signature can take some time. It is up to you if you want to block user actions until everything is finished, but it is not required. If you want to allow user to interact with application, make sure completion and status blocks are not deallocated before everything is completed.
Status block will be called with updated container when signature is successfully added. After that, you don't need to expect any more block calls from this method. Alternatively, status block can be called with error. That also indicates, that method has finished working and no further calls will be made. Other status block calls, where only status is present, can be ignored or used to give updates to user.
If you choose to block user actions while Mobile-ID is used for signing, you may want to allow user to cancel signing if it takes too long.
To cancel Mobile-ID status polling use cancelMobileSignatureStatusPolling method:
[[MoppLibService sharedInstance] cancelMobileSignatureStatusPolling];
MoppLibContainer object gives you basic information about contents of container. If you don't have MoppLibContainer object, you can let MoppLib to create it with method openContainer like this:
NSString *containerPath = @"path/to/container.bdoc";
MoppLibContainerActions *sharedInstance = [MoppLibContainerActions sharedInstance];
[sharedInstance openContainerWithPath:containerPath success:^(MoppLibContainer *container) {
// Got container
} failure:^(NSError *error) {
NSLog(@"Failed to get container: %@", error);
}];
MoppLibContainer will give you a list of signatures and file attached to container. If you need to access one of the files in it, you need to export it somewhere where your application has access.
To extract data file from container and save it use saveDataFile method:
NSString *containerPath = @"path/to/container.bdoc";
NSString *filePath = @"path/to/file/in/container";
NSString *savePath = @"path/where/to/save";
MoppLibContainerActions *sharedInstance = [MoppLibContainerActions sharedInstance];
[sharedInstance container:containerPath saveDataFile:filePath to:savePath success:^{
// File was saved
} failure:^(NSError *error) {
NSLog(@"Failed to save: %@", error);
}];