Skip to Content
SDK IntegrationSwift (iOS & macOS)

iOS SDK

Integrate TrustPin into your iOS application with comprehensive certificate pinning protection.

Platform Requirements

PlatformMinimum Version
iOS13.0+
macOS13.0+
watchOS7.0+
tvOS13.0+
Mac Catalyst13.0+
visionOS2.0+

Swift Version: 5.5+ (requires async/await support)


Installation

Add TrustPin to your project in Xcode:

  1. Go to File → Add Package Dependencies
  2. Enter the repository URL:
    https://github.com/trustpin-cloud/swift.sdk
  3. 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 install

Quick 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:

ApproachBest ForSetup Complexity
URLSessionDelegate (Recommended)Most applications, precise control🟢 Minimal
System-Wide URLProtocolThird-party library protection, legacy code🟡 Medium
Helper MethodsExplicit control, static method preference🟠 Per-request

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

  1. Call TrustPin.setup() only once during app launch
  2. Handle setup errors gracefully - don’t block app launch
  3. Set log level before setup for complete logging
  4. Never call setup concurrently

Security

  1. Use .strict mode in production
  2. Use SPKI or rotate pins before expiration
  3. Monitor pin validation failures
  4. Keep credentials secure (use environment variables)
  5. Use HTTPS for all pinned domains

Performance

  1. Reuse URLSession instances
  2. Use .error or .none log level in production
  3. 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:

TrustPin Swift Documentation 


Resources