Skip to main content

Share Extensions

Receiving Files from Other Apps​

You can receive files from other apps via the iOS and Android Share Sheet, and process them using the Lens SDK.

1. (Prerequisite) Create iOS Share Extension​

To create a Share Extension in your iOS app:

  1. Add Share Extension Target: In Xcode, go to File → New → Target → iOS → Share Extension
  2. Add App Groups Capability: Enable App Groups capability in both your main app and Share Extension to share data between them
  3. Configure Share Extension: Replace the default ShareViewController with your custom implementation
  4. Configure App IDs and Provisioning Profiles: Make sure you create App ID for the Share Extension as well as matching provisioning profiles

2. Configure Share Extension Settings​

Enable share extension mode in your VeryfiLensSettings:

let settings = VeryfiLensReceiptsSettings()
settings.shareExtensionModeIsOn = true

Note: shareExtensionModeIsOn is a mandatory setting in iOS to handle RAM usage restrictions for Share Extensions

3. Configure VeryfiLens in Share Extension​

Configure VeryfiLens with credentials and settings in your ShareViewController:

Using a client-scoped key?

You can set apiKey to a client-scoped Bearer key (full-access or scoped) instead of a Standard key.

let credentials = VeryfiLensCredentials(
clientId: "your_client_id",
username: "your_username",
apiKey: "your_api_key",
url: "your_api_url"
)

let settings = VeryfiLensReceiptsSettings()
settings.shareExtensionModeIsOn = true

VeryfiLens.shared().delegate = self
VeryfiLens.shared().configure(with: credentials, settings: settings) { success in
if success {
// Handle attachment after successful configuration
self.handleAttachment()
}
}

4. Handle Shared Files​

Process the shared files using the uploadImages method:

func handleAttachment() {
guard let extensionItem = extensionContext?.inputItems.first as? NSExtensionItem,
let attachment = extensionItem.attachments?.first else { return }

if attachment.hasItemConformingToTypeIdentifier(UTType.image.identifier) {
attachment.loadItem(forTypeIdentifier: UTType.image.identifier, options: [:]) { [weak self] (data, error) in
if let url = data as? URL {
// uploadImages supports image paths
VeryfiLens.shared().uploadImages(paths: [url.path])
}
}
} else if attachment.hasItemConformingToTypeIdentifier(UTType.pdf.identifier) {
attachment.loadItem(forTypeIdentifier: UTType.pdf.identifier, options: [:]) { [weak self] (data, error) in
if let url = data as? URL {
// uploadImages supports PDF paths too
VeryfiLens.shared().uploadImages(paths: [url.path])
}
}
}
}

5. Implement VeryfiLensDelegate​

Handle the upload results through the delegate methods:

extension ShareViewController: VeryfiLensDelegate {
func veryfiLensSuccess(_ json: [String: Any]) {
// Handle successful upload
}

func veryfiLensError(_ json: [String: Any]) {
// Handle upload error
}

func veryfiLensUpdate(_ json: [String: Any]) {
// Handle progress updates
}
}
danger

Important: The uploadImages method must be called after VeryfiLens.shared().configure has completed successfully.