Headless APIs
The SDK offers several APIs that can be used without instantiating a UIView to display the PDF.
Those APIs are available through the methods WYSIWYSController#acceptAndPrepareDocument and WYSIWYSController#refuseAndPrepareDocument.
The WYSIWYS SDK must be initialized and the document stored prior using the Headless mode using the WYSIWYSController#initWithConfiguration and WYSIWYSController#storeDocument methods.
Store a document
The SDK provides an API to store a document in the WYSIWYS secured storage for a later use.This method must be called before using Headless methods.
[wysController storeDocument:pdf documentID:documentId];Retrieving document's state
Headless APIs have introduced the notion of states for a document. A document can be in one or more of the following states :
WYSDocumentStateNotExist: The document is not present in the secured storageWYSDocumentStateStored: The document has been stored in the secured storageWYSDocumentStatePrepared: The document has been preparedWYSDocumentStateSigned: The document has been signed
A document in state WYSDocumentStatePrepared is necessarily also in state WYSDocumentStateStored, as well as a document in state WYSDocumentStateSigned is necessarily in states WYSDocumentStatePrepared and WYSDocumentStateStored.
It's possible to know the state of a document using one of the following methods :
[wysController documentWithId:documentId inState:state error:&error];
[wysController isDocumentWithId:documentId inState:state];Signing a document
The signature flow for a document is similar to the standard signature, except that no user interaction is possible.
The user interactions are replaced with the following pre-defined behaviour :
- If the handwritten signature is enabled but no signature are stored, handwritten signature will be disabled and the signature will be generated.
- If the handwritten signature is enabled but user has multiple signature stored, the first signature created will be automatically selected.
- If no signature field is available, the document will be signed with an invisible signature
- If multiple signature fields are available, the dedicated field(s) for the user (see previous section) are automatically selected. If the field names do not match any pattern, the first field in PDF dictionnary (not necessarily the first visible field) is automatically selected.
The document can be accepted or refused once an instance of the WYSIWYSController for a given document is created. That's means if your applications needs to process multiple document at once, one instance per contract must be initilized and a reference kept for further use.
- (WYSIWYSController*) wysControllerForContract:(SSCContract*)contract{
WYSIWYSController* wysController = [self.wysiwysControlerList objectForKey:contract.identifier];
if(!wysController){
wysController = [[WYSIWYSController alloc] initWithConfiguration:[self wysConfiguration]];
[self.wysiwysControlerList setObject:wysController forKey:contract.identifier];
}
return wysController;
}Once the event WYSSignatureProcessDelegate#confirmationRequired is emitted by the SDK, the app must confirm the signature using the method WYSIWYSController#confirmSignature on the controller.
[wysController confirmSignature];Retrieving signature info
Once a document is prepared, it's possible to retrieve the signature information, which consist of
- documentDigest : The document digest of the prepared document
- reason : The reason of the signature (
acceptedif document was accepted,refusedif document was refused)
[wysController signatureInfoForDocumentWithId:documentId];Dispose document
When a document is not needed anymore, the app must explicitly dispose the document.
[wysController disposeDocument:documentId];This call will delete all data related to the given document ID, including prepared and signed file.
If the signature process is canceled or aborted, it's possible to dispose only prepared and signed documents.
[wysController disposeDocument:documentId inState:state];Disposing the prepared file will also dispose the signed file.