Create and Store Electronic Signatures from Instant JSON Annotations

Q: How do I store Electronic Signatures in the signature store using annotation provided via Instant JSON?

A: You can use a custom SignatureStore implementation, that populates the signature store with annotations from Instant JSON. This means that those annotations can then be used to create a new signature.

By leveraging the existing KeychainSignatureStore you don’t even have to add the serialization yourself, and therefore all added annotations, that were either added via Instant JSON or via the UI, will be saved to disk.

This is the logic to implement a signature store that accepts Instant JSON to populate it:

class InstantJSONSignatureStore: KeychainSignatureStore {
    func addAnnotationUsingJSON(_ json: String, documentProvider: PDFDocumentProvider) throws {
        guard let jsonData = .utf8) else { return }
        let annotation = try Annotation(fromInstantJSON: jsonData, documentProvider: documentProvider)
        let container = SignatureContainer(signatureAnnotation: annotation, signer: nil, biometricProperties: nil)

And in order to use it, code like this can be used:

let json = "..." // Instant JSON Annotation

let jsonSignatureStore = InstantJSONSignatureStore()

document.didCreateDocumentProviderBlock = { documentProvider in
    try? jsonSignatureStore.addAnnotationUsingJSON(json, documentProvider: documentProvider)

let controller = PDFViewController(document: document) {
    $0.signatureStore = jsonSignatureStore