Ultimately this will be done in App Store Connect. This will also add the StoreKit framework to your project:īefore we do anything else we need to define the products we'll be selling. Note that I moved ContentView.swift into the Shared/Views folder and StoreHelperApp.swift and the Assets catalog into the Shared/Support folder:Ĭheck that your iOS and macOS targets support iOS 15 and macOS 12 respectively:įor both targets, add the In-App Purchase capability. To get started, here's the structure of the Xcode project after creating empty group folders but before we start adding files. StoreHelperDemo was created using Xcode 13 (beta) and the multi-platform app template. I'll introduce features in an as-required manner as we build the app from it's simplest form to a fully-functional demo. The best way to get familiar with StoreKit2 is to create a simple, but full-featured (from an in-app purchase perspective) demo app. Transactions made with one version of StoreKit are immediately available in the other version.Both versions of StoreKit provide the exact same UI experience for users.Both versions of StoreKit provide access to the same in-app purchase product data you configure in the App Store.The good news is that although there are two versions of the StoreKit, both frameworks share a common App Store backend: If you need to support iOS 14 and lower you'll need to continue using StoreKit1.Īpple provides documentation to help you decide which version of StoreKit is right for your app. However, StoreKit2 requires that your app targets iOS 15/macOS 12. Working with in-app purchases using StoreKit2 is a vastly superior experience over using StoreKit1 and you should choose to use it if possible.
This makes working with async APIs much easier and results in a more "natural" flow to your code.StoreKit2 fully embraces the new Async/ Await pattern introduced in Swift 5.5, Xcode 13 and iOS 15: This leads to code that is difficult to read, with program flow being somewhat disjointed.StoreKit1 uses a closure-based method of working with async APIs and notifications: Better still, transactions are now automatically validated by StoreKit2!!.JWS is easy to read - no need for a third-party cryptography library!.StoreKit2 now uses the industry-standard JSON Web Signature ( JWS) format as a secure container for transaction information signed by the App Store: See In-App Purchases with Xcode 12 and iOS 14 for more details. Setting up an app server to communicate with the App Store server (server-based validation).Working with the C-based OpenSSL library to decrypt, read and validate receipt data (on-device validation).With StoreKit1 validating the receipt issued by the App Store was a tricky process that required either: There are two huge changes from the previous (original) version of StoreKit ( StoreKit1 hereafter): Receipt validation What's changed from the original StoreKit? Testing purchases locally using StoreKit configuration files Handling canceled and failed transactionsĮxploring detailed transaction information and history for non-consumables and subscriptions Handling pending ("ask to buy") transactions where parental permission must be obtained before a purchase is completed How to purchase a product and validate the transaction Requesting localized product information from the App Store subscription (VIP plant home care: scheduled home visits to water and care for house plants)Ĭreating a StoreHelper that encapsulates StoreKit2 in-app purchase functionality and makes it easy to work with the App Store.non-consumable (cut flowers, potted plants, chocolates, etc.).consumable (VIP plant installation service: lasts for one day).How to create a multi-platform SwiftUI app that allows users to purchase a range of products, including: Specifically, in building the app we'll cover: The basic premise for the demo is that we're creating an app for an on-line florist that sells a range of flowers, chocolates and other related services like home visits to water and care for house plants.
This SwiftUI app will demonstrate how to use Apple's new StoreKit2 framework to provide in-app purchases to your users. See also In-App Purchases with Xcode 12 and iOS 14 for details of working with the StoreKit1 in iOS 14 and lower. Implementing and testing In-App Purchases with StoreKit2 in Xcode 13, Swift 5.5, iOS 15.