Swift SDK Setup

Introduction

The Capsule SDK for Flutter allows you to easily integrate secure and scalable wallet functionalities into your mobile applications. This guide covers the installation, setup, and usage of the Capsule SDK, including handling authentication flows.

Prerequisites

  • An iOS Swift project.

  • An API key from the Capsule team. Request an API key.

  • Basic knowledge of iOS Swift development.

Setup

Follow these steps to properly set up the Capsule SDK in your project.

1. Add Capsule SDK as a Package Dependency

  1. In your Xcode project. Go to Target -> MyApp -> General -> Frameworks, Libraries, and Embedded Content, and click the + symbol to add a new package dependency.

  2. On the next screen, click Add Other -> Add Package Dependency.

  3. Enter https://github.com/capsule-org/swift-sdk into the search field and select the dependency rule Up to Next Major Version. Ensure the range is 0.0.1 < 1.0.0.

  4. Add the package to the project MyApp.

  5. Ensure Add to Target has MyApp selected, and then click Add Package.

2. Initialize the Capsule SDK

In your iOS project, import the Capsule package and initialize it in your app.

ContentView.swift
import CapsuleSwift

struct ContentView: View {
    @Environment(\.authorizationController) private var authorizationController

    @StateObject var capsule = CapsuleSwift.Capsule(environment: .beta(jsBridgeUrl: nil), apiKey: "<YOUR_API_KEY>")
    @State private var email = ""

    var body: some View {
        ZStack {
            CapsuleWebView(viewModel: capsule).hidden()
            // Your UI components
        }
    }
}
...

3. User and Wallet Creation

To handle user and wallet creation, use the following code snippet as a reference:

UserCreation.swift
...
Button("Sign Up") {
    Task.init {
        try! await capsule.createUser(email: email)
    }
}
.buttonStyle(.bordered)
...

4. User Login

To handle user login, use the following code snippet:

UserLogin.swift
...
Button("Log In") {
Task.init {
try! await capsule.login(authorizationController: authorizationController)
  }
}
...

Examples and Next Steps

While the Swift SDK may not offer the extensive customization options available in the web SDK, it still allows for effective integration in your iOS applications. We encourage you to explore the examples in the SDK repository for practical implementations and signing solutions.

urlhttps://github.com/capsule-org/swift-sdk-example

This example provides a comprehensive guide on how to handle user authentication, wallet creation, and signing messages using the Capsule SDK in a SwiftUI iOS application. Following this example will help you seamlessly integrate Capsule into your project.

For additional integration details, please refer to the documentation in the SDK repository.

page❗Required Customization

Last updated