Hero Image

StoreKit 2 - What has changed?

By Nini - Average reading time: 3 minutes

With StoreKit 2, Apple has released at the WWDC21 a much-improved version of the unwieldy framework we’ve all had to deal with so far.

According to Apple, the main keys to StoreKit 2 are:

  • It’s designed Swift-first
  • Powerful new APIs
  • Simple and secure transactions
  • Customer support
  • Testing Support

So let’s take a brief look to what has changed!

StoreKit 2 Swiftyness

As already mentioned before, StoreKit 2 has been designed with a Swift-first mindset and takes all the advantages like async & await Swift has to offer. This also means that StoreKit 2 is only available for iOS 15 and upwards.

StoreKit 2 vs StoreKit 1

So what’s so swifty about StoreKit 2? to answer the question, let’s just examine the differences between the old and the new version of StoreKit!

StoreKit 1

To fetch products in StoreKit 1 you had to do something like this:

1let request = SKProductsRequest(productIdentifiers: Set(["linkfive.subscription.premium", "linkfive.subscription.light"]))
2request.delegate = self
3request.start()
1extension ExamplePurchases: SKProductsRequestDelegate {
2
3 public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
4 let products = response.products
5 /// Do something with the products
6 }
7
8 public func request(_ request: SKRequest, didFailWithError error: Error) {
9 /// Do something with the error
10 }
11}

So what you basically do, is requesting the products with the given ids and attach the SKProductsRequestDelegate which receives an SKProductsResponse object with the products in it when the request completes. Yikes!

StoreKit 2

Now let’s take a look at the StoreKit 2 way:

1func fetchProducts() async throws -> [Product] {
2 let products = try await Product.request(with: Set(["linkfive.subscription.premium", "linkfive.subscription.light"]))
3 return products
4}

Et voilà! That’s it! No delegate foo anymore, just straight up async/await sugar. If you also look at the other APIs, the new syntax runs through like a red thread. This definitely makes the development much easier and faster than before!

The new APIs

Refunds

Developers are now able to add a “Request refund” button to their apps. A tap on the button opens another form where customers can request a refund with some additional information. The request does not go to the developers themselves, but to Apple, who is going to review the refund.

Invoice / Refunds Lookup

These are basically API’s which return the transaction / refund history for the given customer_order_id.

Conclusion

StoreKit 2 is a huge step into the right direction. It’s API is much cleaner, more understandable and in all ways better to use. It’s definitely a great gift for all the developers out there!

But if you would like to have more control over your subscriptions and manage them properly, you are at the right place! LinkFive will help you to drive your subscription game up. Feel free to sign up now and enjoy the rich advantages we offer to you.


First published on Oct 22, 2021, last updated on Oct 22, 2021

Ready to get started?