# iOS SDK

> Install and initialize the Bolt iOS SDK for checkout, account login, or custom payment flows.

Source: https://help.boltapp.com/developers/sdks/ios-swift

<span id="overview" />

The `BoltCheckoutSDK` package provides client APIs for Bolt Checkout, Bolt account login, and custom payment flows. Install and initialize it once, then continue to the guide for the capability you are building.

## Installation [#installation]

### Swift Package Manager [#swift-package-manager]

Add the Bolt SDK via Xcode:

1. Go to **File > Add Package Dependencies...**
2. Enter the repository URL: `https://github.com/BoltApp/bolt-ios-checkout-sdk`
3. Select the version rule (e.g. "Up to Next Major") and click **Add Package**.

Or add it directly to your `Package.swift`:

```swift title="Swift"
dependencies: [
    .package(url: "https://github.com/BoltApp/bolt-ios-checkout-sdk", from: "0.8.2")
]
```

## SDK initialization [#sdk-initialization]

The SDK must be initialized **exactly once** during your application's lifecycle. The best place to do this is in your `AppDelegate` or SwiftUI `App` entry point.

### UIKit (AppDelegate) [#uikit-appdelegate]

```swift title="Swift"
import BoltCheckoutSDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        BoltCheckout.initialize(
            publishableKey: "YOUR_PUBLISHABLE_KEY",
            merchantDivisionId: "YOUR_MERCHANT_DIVISION_ID",
            environment: .production // or .sandbox
        )

        return true
    }
}
```

### SwiftUI [#swiftui]

```swift title="Swift"
import BoltCheckoutSDK
import SwiftUI

@main
struct MyApp: App {
    init() {
        BoltCheckout.initialize(
            publishableKey: "YOUR_PUBLISHABLE_KEY",
            merchantDivisionId: "YOUR_MERCHANT_DIVISION_ID",
            environment: .production
        )
    }

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}
```

<Warning>
  `BoltCheckout.initialize()` will crash if called more than once. `BoltCheckout.shared` will crash if accessed before `initialize()` has been called.
</Warning>

## Configuration requirements [#configuration-requirements]

To use the SDK, ensure you have the following credentials properly configured:

| Credential           | Where It Lives          | Purpose                                                                                                                  |
| -------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| **Publishable Key**  | Mobile app              | Passed to `BoltCheckout.initialize()`. Safe to embed: it identifies your merchant account but cannot authorize actions.  |
| **Merchant API Key** | Backend server **only** | Used to authenticate `POST /v1/merchant/orders` and other server-side Bolt API calls. **Never embed in the mobile app.** |
| **Order Token**      | Generated per checkout  | Returned by the Merchant Orders API. Passed into `BoltCheckoutConfig` before launching checkout.                         |

## API quick reference [#api-quick-reference]

| Operation             | Simplest Call                                                                                        |
| --------------------- | ---------------------------------------------------------------------------------------------------- |
| Initialize            | `BoltCheckout.initialize(publishableKey: "key", merchantDivisionId: "id", environment: .production)` |
| Checkout (completion) | `BoltCheckout.shared.startCheckout(config: config) { result in ... }`                                |
| Checkout (delegate)   | `BoltCheckout.shared.startCheckout(config: config, delegate: self)`                                  |
| Checkout (VC)         | `present(BoltCheckoutViewController(config: config, delegate: self), animated: true)`                |
| Login (completion)    | `BoltCheckout.shared.startLogin { result in ... }`                                                   |
| Login (delegate)      | `BoltCheckout.shared.startLogin(delegate: self)`                                                     |
| Login (VC)            | `present(BoltLoginViewController(delegate: self), animated: true)`                                   |
| Login with PKCE       | `BoltCheckout.shared.startLogin(loginConfig: BoltLoginConfig(usePkce: true)) { ... }`                |
| Payment flow          | `BoltCheckout.shared.startPaymentFlow(delegate: self)`                                               |
| Authorize payment     | `BoltCheckout.shared.authorizePayment(userInfo: info, orderToken: token, delegate: self)`            |
| Logout                | `BoltCheckout.shared.logOut()`                                                                       |

## Next steps [#next-steps]

* **[iOS checkout](/developers/sdks/ios-swift/checkout/)**: Launch Bolt Checkout with an order token from your backend.
* **[SSO Login](/developers/sdks/ios-swift/sso-login/)**: Authenticate users with their Bolt account via OAuth 2.0 and PKCE.
* **[Custom Checkout](/developers/sdks/ios-swift/custom-checkout/)**: Build a custom checkout using the payment flow and authorization APIs.
* **[API Reference](/developers/sdks/ios-swift/api-reference/)**: Full reference for all delegates, result types, and callbacks.

<span id="cross-platform-parity" />
