What is the best way to implement StoreKit 2 with a StoreView for my subscription based app?

Generated on 9/6/2024

1 search

To implement StoreKit 2 with a StoreView for your subscription-based app, you can follow these steps based on the information from the WWDC sessions:

  1. Set Up StoreKit Configuration: Begin by setting up a StoreKit configuration file with your product metadata. This is essential for getting the in-app purchase UI working with Xcode previews. For more detailed guidance, you can refer to previous WWDC sessions like "What's New in StoreKit Testing" from WWDC 22 and "Introducing StoreKit Testing in Xcode" from WWDC 20.

  2. Declare a Subscription Store View: Create a view for your subscription store. You can start by declaring a subscription store view and providing the group ID for your subscription. This is a straightforward process that allows you to structure your store to display different subscription levels.

  3. Use Swift Async/Await: Utilize the Swift Async/Await pattern to perform tasks such as fetching product metadata, purchasing, and retrieving customer transaction history. This modern approach simplifies handling in-app purchases.

  4. Customize Subscription Store Views: You can customize the appearance of your subscription store. Starting in iOS 18, you can create custom control styles to match your app's design. This involves declaring a type that conforms to the subscription store control style protocol and using the new subscription picker API.

  5. Implement Preferred Subscription Offers: Use the Preferred Subscription Offer API to control which offer to display when multiple offers are available. This API allows you to fetch offer metadata and set up purchases, providing flexibility in how you present subscription options to users.

  6. Test in Xcode: Leverage StoreKit testing in Xcode to ensure your in-app purchase flows work as expected. This includes testing privacy policies and license agreements locally, which can be done with the new settings in Xcode 16.

For more detailed information, you can refer to the session What’s new in StoreKit and In-App Purchase (15:35) for testing in Xcode and Implement App Store Offers (19:55) for using the Preferred Subscription Offer API.