Adapty iOS SDK Documentation

repository·master·Indexed 19 days ago

https://github.com/adaptyteam/adaptysdk-ios

An open-source, native iOS SDK for simplifying in-app subscription integration. It provides server-side receipt validation, a no-code Paywall Builder for designing native flows, A/B testing for pricing and designs, and comprehensive subscription management including free trials, upgrades, and renewals.

Tokens
1.1K
Snippets
4
Records
6
Agent score
67%

What's inside Adapty SDK for iOS

  1. Overview of Adapty SDK capabilities

    master

    Adapty is a lightweight, native, and open-source framework designed to accelerate in-app subscription implementation for iOS.

    Key features include:

    • No Server Code: Handles server-side receipt validation automatically.
    • No-Code Flow Builder: Visually design single or multi-screen flows (paywalls, onboardings, surveys) that are rendered natively in your app.
    • A/B Testing: Test different prices, designs, and offers without requiring new app releases.
    • Subscription Management: Supports free trials, upgrades, downgrades, crossgrades, family sharing, renewals, and promo offers.
    • Advanced Analytics: Real-time metrics with filtering by attribution, campaign, and user segments.
  2. Understand the AdaptyRecipes-SwiftUI Demo App structure

    master

    The AdaptyRecipes-SwiftUI demo app serves as a tutorial and reference implementation for integrating Adapty's Paywall Builder into SwiftUI applications. It demonstrates how to handle access control using placements and how to manage user profiles for testing.

    Key Components:

    1. Recipes Tab: Simulates a real-world application interface with two access levels:

      • Basic Recipes: Accessible to all users.
      • Premium Recipes: Accessible only to paying users. If an unauthorized user attempts to access a Premium Recipe, a paywall is triggered.
      • Placements: In this app, each subcategory within 'Premium Recipes' represents an Adapty placement. You can configure which paywall is shown for a specific placement via the Adapty Dashboard.
    2. Profile Tab: An auxiliary testing interface that allows you to:

      • Log in with different user accounts to test various access levels.
      • View and copy the current Profile ID to locate the user in the Adapty Dashboard Profiles section.
      • Inspect the current user's subscription and non-subscription purchase counts.
  3. Explore Adapty SwiftUI Demo Apps

    master

    Adapty provides demo applications designed to serve as both tutorials and practical examples for implementing paywalls. These apps demonstrate how to work with paywalls designed via the Adapty Paywall Builder.

    For a modern implementation using SwiftUI and Swift Package Manager (SPM), refer to the AdaptyRecipes-SwiftUI repository.

    // Refer to AdaptyRecipes-SwiftUI for specific SwiftUI implementation patterns
  4. Update the Adapty iOS SDK version using update_version.sh

    master

    To update the SDK version across the entire project, use the update_version.sh script. This ensures consistency by updating the version in Sources/Versions.swift (the main SDK version constant) and Sources.AdaptyPlugin/cross_platform.yaml (the cross-platform schema version).

    Important: Do not manually edit version numbers in individual files. Always use this script to avoid desynchronization.

    Version Formats Supported:

    • x.y.z (e.g., 3.12.0)
    • x.y.z-SUFFIX (e.g., 3.12.0-SNAPSHOT)
    # From project root directory
    ./scripts/update_version.sh <new_version>
    
    # Examples
    ./scripts/update_version.sh 3.12.0
    ./scripts/update_version.sh 3.12.0-SNAPSHOT
  5. Initialize the Adapty SDK

    master

    To start using Adapty in your iOS application, you must first activate the SDK using your unique App Key. This should be done early in your app's lifecycle (e.g., in AppDelegate or your app's entry point).

    import Adapty
    
    Adapty.activate("YOUR_APP_KEY")
  6. Make an in-app purchase with Adapty.makePurchase()

    master

    Adapty simplifies the purchase process by handling receipt validation and subscription management. You can trigger a purchase by calling Adapty.makePurchase(product:). The method returns a result that indicates whether the purchase was successful or if an error occurred.

    Use the following pattern to handle the purchase result:

    // Make a purchase, Adapty handles the rest
    Adapty.makePurchase(product: product) { [weak self] result in
        switch result {
        case let .success(profile):
            // check access level using the returned profile
        case let .failure(error):
            // handle error
        }
    }
    // Make a purchase, Adapty handles the rest
    Adapty.makePurchase(product: product) { [weak self] result in
        switch result {
        case let .success(profile):
            // check access level
        case let .failure(error):
            // handle error
        }
    }