iOS SDK
Integrate TrustPin into your iOS application with comprehensive certificate pinning protection.
Platform Requirements
| Platform | Minimum Version |
|---|---|
| iOS | 13.0+ |
| macOS | 13.0+ |
| watchOS | 7.0+ |
| tvOS | 13.0+ |
| Mac Catalyst | 13.0+ |
| visionOS | 2.0+ |
Swift Version: 5.5+ (requires async/await support)
Installation
Swift Package Manager (Recommended)
Add TrustPin to your project in Xcode:
- Go to File → Add Package Dependencies
- Enter the repository URL:
https://github.com/trustpin-cloud/swift.sdk - Select version 4.0.0 or later
Package.swift
For command-line projects:
dependencies: [
.package(url: "https://github.com/trustpin-cloud/swift.sdk", from: "4.0.0")
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "TrustPinKit", package: "TrustPin-Swift")
]
)
]CocoaPods
Add to your Podfile:
pod 'TrustPinKit', '~> 4.0.0'Then run:
pod installQuick Start
1. Get Your Credentials
Sign in to the TrustPin Dashboard and retrieve:
- Organization ID
- Project ID
- Public Key (Base64-encoded)
2. Initialize TrustPin
Add this to your app’s initialization (e.g., AppDelegate or @main struct):
import TrustPinKit
class AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Task {
do {
try await TrustPin.setup(
organizationId: "your-org-id",
projectId: "your-project-id",
publicKey: "your-base64-public-key",
mode: .strict
)
print("TrustPin initialized")
} catch {
print("TrustPin setup failed: \(error)")
}
}
return true
}
}Integration Approaches
TrustPin offers three integration methods:
| Approach | Best For | Setup Complexity |
|---|---|---|
| URLSessionDelegate (Recommended) | Most applications, precise control | 🟢 Minimal |
| System-Wide URLProtocol | Third-party library protection, legacy code | 🟡 Medium |
| Helper Methods | Explicit control, static method preference | 🟠 Per-request |
URLSessionDelegate (Recommended)
For granular control over specific URLSession instances:
import TrustPinKit
class NetworkManager {
private let trustPinDelegate = TrustPinURLSessionDelegate()
private lazy var session = URLSession(
configuration: .default,
delegate: trustPinDelegate,
delegateQueue: nil
)
func fetchData() async throws -> Data {
let url = URL(string: "https://api.example.com/data")!
let (data, _) = try await session.data(from: url)
return data
}
}Best Practices
Setup & Initialization
- Call
TrustPin.setup()only once during app launch - Handle setup errors gracefully - don’t block app launch
- Set log level before setup for complete logging
- Never call setup concurrently
Security
- Use
.strictmode in production - Use SPKI or rotate pins before expiration
- Monitor pin validation failures
- Keep credentials secure (use environment variables)
- Use HTTPS for all pinned domains
Performance
- Reuse URLSession instances
- Use
.erroror.nonelog level in production - Initialize early to avoid delays
Complete Documentation
For detailed information on all integration approaches, advanced configuration, error handling, and production deployment, visit the complete documentation:
Resources
- Repository: github.com/trustpin-cloud/swift.sdk
- Swift API Docs: trustpin-cloud.github.io/swift.sdk
- Dashboard: app.trustpin.cloud
- Support: support@trustpin.cloud