What's New / Privacy, Security & Identity

What's new in _StoreKit_SwiftUI

+1 New~1 DeprecatediOS · macOS · visionOS

_StoreKit_SwiftUI is a Swift cross-import overlay: the API Swift surfaces when a target imports both StoreKit and SwiftUI. It adds SwiftUI View modifiers for in-app purchase and subscription flows, including offer code redemption.

One new API and one deprecation on the same symbol, View.offerCodeRedemption. The view modifier is added and marked deprecated in this SDK. No APIs were removed.

New

1
func

View.offerCodeRedemption

NewiOSmacOS
nonisolated public func offerCodeRedemption(options: Set<RedeemOption>, isPresented: Binding<Bool>, onCompletion: @escaping @MainActor (Result<VerificationResult<Transaction>, any Error>) -> Void) -> some View

Presents a sheet that enables customers to redeem offer codes that you configure in App Store Connect.

The offerCodeRedemption(options:isPresented:onCompletion:) method displays a system sheet where customers can enter and redeem offer codes. If you generate offer codes in App Store Connect, call this method to enable customers to redeem the offer. To display the sheet using UIKit, see presentOfferCodeRedeemSheet(from:options:).

Important: Set up offer codes in App Store Connect before calling this API. Customers can only redeem these offers in your app through the redemption sheet; don’t use a custom UI. For more information, see <doc://com.apple.documentation/documentation/storekit/appstore/supporting_subscription_offer_codes_in_your_app>.

The following code example shows a view that displays the offer code redemption sheet when the customer taps a button:

import SwiftUI
import StoreKit

struct ContentView: View {
    @State private var redeemSheetIsPresented = false

    var body: some View {
        Button("Present offer code redemption sheet.") {
            redeemSheetIsPresented = true
        }
        .offerCodeRedemption(
            options: [],
            isPresented: $redeemSheetIsPresented
        ) { result in
            // Handle result
        }
    }
}

When the customer successfully redeems an offer code, the system delivers the resulting transaction through onCompletion, as a VerificationResult that wraps the Transaction.

Parameters

options
A set of RedeemOption values that configure the code redemption.
isPresented
A binding to a Boolean value that determines whether the system displays the sheet. You set the Boolean value to true to cause the system to display the sheet. The system sets it to false when it dismisses the sheet.
onCompletion
A closure the system calls with the result of the redemption. On success, the closure receives a VerificationResult containing the Transaction that the redemption produces. On failure, it receives the error that caused the redemption to fail.

Deprecated

1
func

View.offerCodeRedemption

DeprecatediOSmacOSvisionOS
nonisolated public func offerCodeRedemption(isPresented: Binding<Bool>, onCompletion: @escaping @MainActor (Result<Void, any Error>) -> Void = { _ in }) -> some View

Presents a sheet that enables customers to redeem offer codes that you configure in App Store Connect.

The offerCodeRedemption(isPresented:onCompletion:) method displays a system sheet where customers can enter and redeem offer codes. If you generate offer codes in App Store Connect, call this function to enable customers to redeem the offer. To display the sheet using UIKit, see presentOfferCodeRedeemSheet(in:).

Important: Set up offer codes in App Store Connect before calling this API. Customers can only redeem these offers in your app through the redemption sheet; don’t use a custom UI. For more information, see <doc://com.apple.documentation/documentation/storekit/appstore/supporting_subscription_offer_codes_in_your_app>.

The following code example shows a view that displays the offer code redemption sheet upon a button press:

import SwiftUI
import StoreKit

struct ContentView: View {
    @State private var redeemSheetIsPresented = false

    var body: some View {
        Button("Present offer code redemption sheet.") {
            redeemSheetIsPresented = true
        }
        .offerCodeRedemption(isPresented: $redeemSheetIsPresented) { result in
            // Handle result
        }
    }
}

When customers redeem an offer code, StoreKit emits the resulting transaction in <doc://com.apple.documentation/documentation/storekit/transaction/updates>. Set up a transaction listener as soon as your app launches to receive new transactions while the app is running.

Parameters

isPresented
A binding to a Boolean value that determines whether the system displays the sheet. You set the Boolean value to true to cause the system to display the sheet. The system sets it to false when it dismisses the sheet.
onCompletion
A closure that returns the result of the presentation. In Mac apps built with Mac Catalyst, the completion handler returns a failure with an error prior to macOS 15.

No APIs match your filter.

← More in Privacy, Security & Identity