Warning
This library is currently in alpha and the API will likely change. Do not use for anything other than early testing.
This project provides iOS bindings to the C2PA (Content Authenticity Initiative) libraries. It wraps the C2PA Rust implementation (c2pa-rs) using its C API bindings.
C2PA iOS offers:
- iOS/macOS support via Swift Package/XCFramework
- Native Swift APIs for reading, verifying, and signing content with C2PA manifests
- Stream-based APIs for flexible data handling
- Builder APIs for creating custom manifests
- Comprehensive test suite with example application
/src
- Swift wrapper source code/template
- Swift package template/example
- Example iOS application/output
- Build output artifacts/build
- Temporary build files and external dependencies/Makefile
- Build system commands
- iOS 15.0+ / macOS 11.0+
- Xcode 13.0+
- Swift 5.7+
- Rust (latest stable version)
- Xcode Command Line Tools
- Make
You can add C2PA iOS as a Swift Package Manager dependency:
dependencies: [
.package(url: "https://github.com/contentauth/c2pa-ios.git", from: "0.0.1")
]
In your target, add the dependency:
targets: [
.target(
name: "YourTarget",
dependencies: [.product(name: "C2PA", package: "c2pa-ios")]
)
]
For local development without using a released version:
- Build the iOS framework with
make ios-framework
(ormake ios-dev
for faster Apple Silicon development builds) - Add the resulting package in
output/C2PA-iOS
to your project:- In Xcode: File ??? Add Package Dependencies ??? Add Local...
- Navigate to the
output/C2PA-iOS
directory and add it
The Makefile downloads pre-built binaries from GitHub releases, eliminating the need to build the Rust components locally.
import C2PA
// Read C2PA data from a file
do {
let manifestJSON = try C2PA.readFile(at: imageURL)
print("C2PA manifest: \(manifestJSON)")
} catch {
print("Error reading C2PA data: \(error)")
}
// Sign a file with C2PA data
let signerInfo = SignerInfo(
algorithm: .es256,
certificatePEM: certificatePEM,
privateKeyPEM: privateKeyPEM,
tsaURL: nil
)
let manifestJSON = """
{
"claim_generator": "MyApp/1.0",
"title": "Signed Image",
"format": "image/jpeg"
}
"""
try C2PA.signFile(
source: inputURL,
destination: outputURL,
manifestJSON: manifestJSON,
signerInfo: signerInfo
)
// Create stream from data
let imageData = try Data(contentsOf: imageURL)
let stream = try Stream(data: imageData)
// Read with Reader API
let reader = try Reader(format: "image/jpeg", stream: stream)
let manifestJSON = try reader.json()
// Sign with Builder API
let builder = try Builder(manifestJSON: manifestJSON)
let signer = try Signer(info: signerInfo)
let sourceStream = try Stream(data: imageData)
let destStream = try Stream(fileURL: outputURL)
let manifestData = try builder.sign(
format: "image/jpeg",
source: sourceStream,
destination: destStream,
signer: signer
)
-
Clone this repository:
git clone https://github.com/contentauth/c2pa-ios.git cd c2pa-ios
-
Build the iOS framework (downloads pre-built binaries automatically):
# iOS framework (device + simulator) make ios-framework # For faster development on Apple Silicon Macs make ios-dev # Only builds for arm64 simulator
-
Check built outputs:
# iOS Swift Package open output/C2PA-iOS # Example App open example
The project includes a comprehensive Makefile with various targets:
setup
- Create necessary directoriesdownload-binaries
- Download pre-built binaries from GitHub releasesios-framework
- Create iOS XCFramework (default target)ios-dev
- Build iOS library for arm64 simulator only (optimized for Apple Silicon)clean
- Remove build artifactshelp
- Show all available targets
The build system downloads pre-built Rust binaries from GitHub releases, eliminating the need for local Rust compilation.
The example iOS application in the example
directory demonstrates comprehensive C2PA functionality:
- C2PA Library Version - Display current library version
- Error Handling - Proper error handling for invalid files
- Reading C2PA Data - Extract manifest data from signed images
- Stream APIs - Demonstrate flexible stream-based operations
- Builder APIs - Sign images with custom manifest data
- No-Embed Manifests - Create cloud/sidecar manifests
- Resource Management - Add and extract resources (thumbnails, etc.)
- Ingredient Support - Handle ingredient relationships
- Archive Operations - Work with C2PA archives
- Custom Signers - Implement callback-based signing
The app includes 19 comprehensive tests covering all major C2PA operations. Run the app and tap "Run All Tests" to see the library in action.
This project is licensed under the Apache License, Version 2.0 and MIT - see the LICENSE-APACHE and LICENSE-MIT files for details.