For years we had support for in-app purchases in MBS Xojo Plugins using the StoreKit framework from Apple for macOS or iOS. You can use that to have users try your application and then pay for them to unlock the full version of the app. The StoreKit framework got deprecated, but is still working well.
A few years ago Apple started to write a new StoreKit framework in Swift. The new framework offers many more features developer asked for:
- Modern asynchronous API. StoreKit 2 leverages Swift’s async/await concurrency model, replacing legacy delegate or callback-heavy approaches with clean, readable, and more maintainable code.
- Automatic Cryptographic ValidationTransactions in StoreKit 2 are automatically cryptographically validated using JSON Web Signature (JWS). This adds a strong layer of security and eliminates the burden of manually validating receipts or transactions.
- Enhanced Transaction History & Subscription DataConsumables history now includes completed consumable purchases (not just unfinished ones). Subscription and transaction histories are richer, supporting renewal info, and work across app launches or even device changes.
- Backward Compatibility via Back DeploymentThanks to Swift’s @backDeploy attribute, StoreKit 2 APIs can access new App Store features on older OS versions—even when the user isn’t on the latest iOS. This lets developers adopt StoreKit 2 gradually without sacrificing functionality.
- Improved Testing in XcodeXcode’s StoreKit testing framework has been enhanced, allowing developers to test scenarios like promotional offers, privacy policy displays, license agreements, localized subscription group names, Win-Back offers, and extended StoreKit configuration options—all within the sandbox environment.
- Subscription & Offer AdvancementsWin-Back offers allow targeting churned subscribers with tailored re-engagement campaigns set up directly in App Store Connect—no custom code necessary.Expanded Offer Code support—offer codes now work not only for auto-renewable subscriptions but also for consumables, non-consumables, and non-renewing subscriptions.New API fields like offerPeriod and advancedCommerceInfo, plus properties like appTransactionID and originalPlatform, provide richer transaction metadata.
- In-App Subscription Management & Refund RequestsUsers can manage subscriptions and request refunds directly within the app—no redirection to the App Store required.
When we created our brigde between Xojo ⇔ C++ ⇔ Swift we designed it with a few goals:
- One central StoreKit2MBS module with all the methods and properties.
- Asynchronous APIs with delegates.
- Conversion of Swift structures to Xojo dictionaries.
- Reporting errors via exceptions or error message parameters.
- Work often happens on background threads, but delegates are called on main threads.
- Compatible for all macOS and iOS versions.
In general you need iOS 15.0 or macOS 12.0 to use StoreKit. A couple of APIs require newer versions and a couple of properties are only showing up in dictionaries when running in a newer version. For example the requestReview method works only on macOS 13.0 or iOS 16.0. If called on an older version, the method will do nothing.
When you want to use this new module, you may first read in Apple’s documentation to get an idea how the APIs work. Then you may check our documentation and example project.
To get the sample project running, you need:
- An Apple developer account
- Register an app in App Store Connect
- Change the bundle identifier and name of the sample to use your identifier and name.
- Define products for your application in App Store Connect. They need a unique identifier of your choice, a name and a price.
- Change the sample project to pass the identifiers you defined for your products to the StoreKit2MBS.QueryProducts method call.
For the 25.4 version we include a first version. No views, no refunds and a few other things may be missing. Future versions will add more based on your feedback. Please try it and let us know if you have questions.