Skip to main content
iOS Integration
Learn how to integrate the IgniSign signature interface into your iOS applications

Overview

The IgniSign iOS SDK allows you to integrate electronic signatures directly into your iOS applications, providing a seamless experience for your users. The SDK handles the complexities of document presentation, identity verification, signature capture, and legal compliance.

Integration Flow

The general flow for integrating the signature interface into iOS applications follows these steps:

Installation

To get started with the IgniSign iOS SDK, add it to your project by following these steps:

Using CocoaPods

CocoaPods is a dependency manager for iOS projects. To integrate IgniSign into your Xcode project using CocoaPods, follow these steps:

  1. Create or edit your Podfile in your project directory:
# Podfile
platform :ios, '12.0'

target 'YourApp' do
use_frameworks!

# Add the IgniSign iOS SDK
pod 'ignisign-ios'
end
  1. Run the CocoaPods installer:
pod install
  1. Open the .xcworkspace file that CocoaPods created:
open YourApp.xcworkspace
Using Swift Package Manager

If you prefer Swift Package Manager, follow these steps:

  1. In Xcode, select "File" → "Swift Packages" → "Add Package Dependency..."
  2. Enter the repository URL: https://github.com/ignisign/ignisign-ios.git
  3. Select the version you want to use
  4. Click "Next" and then "Finish"

Implementation Steps

1
Create Ignisign Instance
Create an instance of Ignisign as a webview
2
Configure WebView
Define a WKWebViewConfiguration to enable communication
3
Configure Session Parameters
Create instances of IgnisignSignatureSessionDimensions, IgnisignJSSignatureSessionsDisplayOptions, and IgnisignInitParams
4
Set Up View
Call setValues() and initSignatureSession()
5
Implement Callbacks
Extend IgnisignJS_SignatureSession_Callbacks in your ViewController

Basic Implementation

Here's a step-by-step guide to implementing IgniSign in your iOS application:

1. Import the SDK

First, import the IgniSign SDK in your Swift file:

import UIKit
import ignisign_ios
import WebKit
2. Create a Signature View Controller

Create a view controller to handle the signature process:

class SignatureViewController: UIViewController, IgnisignJS_SignatureSession_Callbacks {
  
  // Properties for signature request
  var signatureRequestId: String!
  var signerId: String!
  var signatureSessionToken: String! // Session token from your backend
  var signerAuthSecret: String! // Required for embedded integration
  
  // IgniSign webview
  var ignisignWebView: Ignisign!
  
  override func viewDidLoad() {
      super.viewDidLoad()
      
      // Create a WKWebViewConfiguration
      let webViewConfiguration = WKWebViewConfiguration()
      
      // Initialize the IgniSign webview
      ignisignWebView = Ignisign(frame: view.bounds, configuration: webViewConfiguration)
      ignisignWebView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
      view.addSubview(ignisignWebView)
      
      // Configure session dimensions
      let dimensions = IgnisignSignatureSessionDimensions(
          width: "100%",
          height: "100%"
      )
      
      // Configure display options
      let displayOptions = IgnisignJSSignatureSessionsDisplayOptions(
          hideTitle: true
      )
      
      // Set initialization parameters
      let initParams = IgnisignInitParams(
          signatureRequestId: signatureRequestId,
          signerId: signerId,
          signatureSessionToken: signatureSessionToken, // Session token from your backend
          signerAuthSecret: signerAuthSecret, // Required for embedded integration
          dimensions: dimensions,
          displayOptions: displayOptions
      )
      
      // Set values and initialize session
      ignisignWebView.setValues(initParams: initParams)
      ignisignWebView.initSignatureSession()
  }
  
  // MARK: - IgnisignJS_SignatureSession_Callbacks
  
  func onSignatureSessionCompleted(data: String) {
      // Handle successful signature completion
      print("Signature completed: \(data)")
      let alert = UIAlertController(title: "Success", message: "Signature completed successfully", preferredStyle: .alert)
      alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in
          self.navigationController?.popViewController(animated: true)
      })
      present(alert, animated: true)
  }
  
  func onSignatureSessionError(error: String) {
      // Handle signature error
      print("Signature error: \(error)")
      let alert = UIAlertController(title: "Error", message: "An error occurred: \(error)", preferredStyle: .alert)
      alert.addAction(UIAlertAction(title: "OK", style: .default))
      present(alert, animated: true)
  }
  
  func onSignatureSessionCanceled(reason: String) {
      // Handle signature cancellation
      print("Signature canceled: \(reason)")
      let alert = UIAlertController(title: "Canceled", message: "Signature process was canceled", preferredStyle: .alert)
      alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in
          self.navigationController?.popViewController(animated: true)
      })
      present(alert, animated: true)
  }
  
  func onSignatureSessionProgress(progress: String) {
      // Handle signature progress updates
      print("Progress: \(progress)")
  }
}
3. Present the Signature View Controller

Now, you can present this view controller when a user needs to sign a document:

// In your document list view controller
func startSignatureProcess(signatureRequestId: String, signerId: String) {
  let signatureVC = SignatureViewController()
  signatureVC.signatureRequestId = signatureRequestId
  signatureVC.signerId = signerId
  
  // Present the view controller
  navigationController?.pushViewController(signatureVC, animated: true)
}

Advanced Implementation

Using SwiftUI

If you're using SwiftUI, you can wrap the IgniSign view in a UIViewRepresentable:

import SwiftUI
import ignisign_ios
import WebKit

struct IgnisignView: UIViewRepresentable {
  var signatureRequestId: String
  var signerId: String
  var onComplete: (String) -> Void
  var onError: (String) -> Void
  var onCancel: (String) -> Void
  var onProgress: (String) -> Void
  
  func makeCoordinator() -> Coordinator {
      Coordinator(self)
  }
  
  func makeUIView(context: Context) -> Ignisign {
      // Create a WKWebViewConfiguration
      let webViewConfiguration = WKWebViewConfiguration()
      
      // Initialize the IgniSign webview
      let ignisignWebView = Ignisign(frame: .zero, configuration: webViewConfiguration)
      
      // Set the delegate
      context.coordinator.ignisignWebView = ignisignWebView
      
      // Configure session dimensions
      let dimensions = IgnisignSignatureSessionDimensions(
          width: "100%",
          height: "100%"
      )
      
      // Configure display options
      let displayOptions = IgnisignJSSignatureSessionsDisplayOptions(
          hideTitle: true
      )
      
      // Set initialization parameters
      let initParams = IgnisignInitParams(
          signatureRequestId: signatureRequestId,
          signerId: signerId,
          dimensions: dimensions,
          displayOptions: displayOptions
      )
      
      // Set values and initialize session
      ignisignWebView.setValues(initParams: initParams)
      ignisignWebView.initSignatureSession()
      
      return ignisignWebView
  }
  
  func updateUIView(_ uiView: Ignisign, context: Context) {
      // Update the view if needed
  }
  
  class Coordinator: NSObject, IgnisignJS_SignatureSession_Callbacks {
      var parent: IgnisignView
      var ignisignWebView: Ignisign?
      
      init(_ parent: IgnisignView) {
          self.parent = parent
      }
      
      func onSignatureSessionCompleted(data: String) {
          parent.onComplete(data)
      }
      
      func onSignatureSessionError(error: String) {
          parent.onError(error)
      }
      
      func onSignatureSessionCanceled(reason: String) {
          parent.onCancel(reason)
      }
      
      func onSignatureSessionProgress(progress: String) {
          parent.onProgress(progress)
      }
  }
}

// Usage in a SwiftUI view
struct SignatureView: View {
  @State private var showingSuccess = false
  @State private var showingError = false
  @State private var errorMessage = ""
  @Environment(.presentationMode) var presentationMode
  
  var signatureRequestId: String
  var signerId: String
  
  var body: some View {
      IgnisignView(
          signatureRequestId: signatureRequestId,
          signerId: signerId,
          onComplete: { data in
              showingSuccess = true
          },
          onError: { error in
              errorMessage = error
              showingError = true
          },
          onCancel: { _ in
              presentationMode.wrappedValue.dismiss()
          },
          onProgress: { progress in
              print("Progress: \(progress)")
          }
      )
      .alert(isPresented: $showingSuccess) {
          Alert(
              title: Text("Success"),
              message: Text("Signature completed successfully"),
              dismissButton: .default(Text("OK")) {
                  presentationMode.wrappedValue.dismiss()
              }
          )
      }
      .alert(isPresented: $showingError) {
          Alert(
              title: Text("Error"),
              message: Text("An error occurred: \(errorMessage)"),
              dismissButton: .default(Text("OK"))
          )
      }
  }
}
Customizing the Signature Interface

You can customize the appearance and behavior of the signature interface:

// Create display options with advanced customizations
let displayOptions = IgnisignJSSignatureSessionsDisplayOptions(
  hideTitle: true,                 // Hide the title bar
  darkMode: true,                  // Enable dark mode
  hideProgressBar: false,          // Show progress bar
  customCSS: "body { background-color: #f5f5f5; }", // Custom CSS
  logo: "https://your-company.com/logo.png", // Custom logo
  primaryColor: "#007bff"          // Custom primary color
)

// Create initialization parameters with the custom display options
let initParams = IgnisignInitParams(
  signatureRequestId: signatureRequestId,
  signerId: signerId,
  dimensions: dimensions,
  displayOptions: displayOptions,
  lang: "fr"                       // Set language to French
)
Error Handling

Implement comprehensive error handling to provide a better user experience:

func onSignatureSessionError(error: String) {
  print("Signature error: \(error)")
  
  // Try to parse the error as JSON
  if let data = error.data(using: .utf8),
     let errorDict = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
     let errorCode = errorDict["code"] as? String,
     let errorMessage = errorDict["message"] as? String {
      
      // Handle specific error codes
      switch errorCode {
      case "NETWORK_ERROR":
          // Handle network connectivity issues
          showNetworkErrorAlert()
      case "AUTH_ERROR":
          // Handle authentication errors
          showAuthErrorAlert()
      case "SESSION_EXPIRED":
          // Handle session expiration
          refreshSession()
      default:
          // Handle other errors
          let alert = UIAlertController(title: "Error", message: errorMessage, preferredStyle: .alert)
          alert.addAction(UIAlertAction(title: "OK", style: .default))
          present(alert, animated: true)
      }
  } else {
      // Handle plain text error
      let alert = UIAlertController(title: "Error", message: error, preferredStyle: .alert)
      alert.addAction(UIAlertAction(title: "OK", style: .default))
      present(alert, animated: true)
  }
}

Production Considerations

Security

When implementing the IgniSign SDK in production, consider these security best practices:

  • API Key Security: Store your API keys securely, preferably on your server side
  • HTTPS: Ensure all communications use HTTPS
  • Signature Token Handling: Generate signature tokens server-side to prevent tampering
  • User Authentication: Properly authenticate users before initiating signature requests
  • WKWebView Security: Configure WKWebView with secure settings
Performance

Optimize performance for a smooth user experience:

  • Resource Loading: Initialize the SDK only when needed
  • Memory Management: Release resources properly in deinit/viewDidDisappear
  • Network Handling: Implement proper network state detection and recovery
  • Background Processing: Handle application state changes properly
User Experience

Enhance the user experience with these tips:

  • Loading States: Show proper loading indicators during initialization
  • Error Messages: Provide clear and actionable error messages
  • Orientation Changes: Handle device orientation changes properly
  • Navigation: Implement intuitive navigation flows around the signature process
  • Accessibility: Ensure the signature process is accessible to all users

Common Issues and Solutions

IssueSolution
WKWebView JavaScript errorsEnable JavaScript debugging in WKWebView by setting configuration.preferences.setValue(true, forKey: "developerExtrasEnabled").
Network connectivity issuesUse NWPathMonitor to detect network state changes and handle offline scenarios gracefully.
SDK initialization failuresEnsure all required parameters are provided and network connectivity is available.
Memory leaksProperly release the Ignisign view and clean up resources in deinit.

Next Steps

Now that you understand how to integrate the IgniSign signature interface into your iOS applications, you might want to explore: