> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crycketpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS

> Integrate Crycket into your iOS app with Swift

## Installation

Add the Crycket SDK via Swift Package Manager:

```
https://github.com/crycket/crycket-ios-sdk
```

## Setup

Initialize the SDK at app startup:

```swift theme={null}
import CrycketSDK

let sdk = PaymentSDK.init(
  apiKey: "pk_live_...",
  debug: false
)
```

## Wallet interface

Implement the `PaymentWallet` protocol for your wallet provider:

```swift theme={null}
class MyWallet: PaymentWallet {
  var address: String { get { return walletAddress } }
  var chain: CAIP2ChainId { get { return .solana } }

  func signTransaction(_ tx: UnsignedTransaction) async throws -> SignedTransaction {
    // Sign with your wallet provider
  }
}
```

## Requesting a payment

```swift theme={null}
// 1. Create an intent
let intent = try await sdk.createIntent(
  chain: "solana:5eykt4UsFv8P8NJdTREpY1vzqKq2Kvdp",
  token: "USDC",
  amount: "10.50",
  requestor: wallet.address,
  idempotencyKey: "order_982734"
)

// 2. Start audio broadcast
let broadcast = sdk.broadcast(intent)

// 3. Watch for fulfillment
sdk.onStatusChange(intent) { status, context in
  if status == .confirmed {
    broadcast.stop()
    // Payment complete
  }
}
```

## Fulfilling a payment

```swift theme={null}
// 1. Listen for audio signal
let received = try await sdk.listen()

// 2. Handle with default UI
sdk.onIntentReceived(received.intentId, wallet: wallet)

// Or headless mode for custom UI
sdk.onIntentReceived(received.intentId, wallet: wallet,
  headless: true,
  onDetails: { intent, summary in
    // Render payment details
  },
  onComplete: { intent in
    // Payment confirmed
  },
  onError: { error in
    // Handle error
  }
)
```
