内购如何迁移到StoreKit2

Generated on 2/10/2025

1 search

To migrate your in-app purchases to StoreKit 2, you should consider the following steps as highlighted in the session "What’s new in StoreKit and In-App Purchase" from WWDC 2024:

  1. Deprecation of Original API: The original API for in-app purchases is deprecated starting with iOS 18. While existing apps will continue to function, the legacy API will not receive new features or enhancements. Therefore, it's recommended to update your app to use StoreKit 2.

  2. Benefits of StoreKit 2: StoreKit 2 offers several improvements, such as:

    • Access to customer transaction history and subscription renewal information.
    • Automatic cryptographic validation.
    • Utilization of modern language features like Swift's Async/Await pattern for tasks such as fetching product metadata and purchasing.
    • Backward compatibility with older operating systems through the back-deployed attribute in Swift.
  3. Testing and Implementation: StoreKit 2 provides a suite of tools to simplify handling in-app purchases. You can test your in-app purchase flows using StoreKit testing in Xcode, which allows you to simulate purchase intents and billing issues directly in your app.

For more detailed guidance, you can refer to the Update to StoreKit 2 (21:06) section of the session.