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:

let request = SKProductsRequest(productIdentifiers: Set(["linkfive.subscription.premium", "linkfive.subscription.light"]))
request.delegate = self
request.start()
extension ExamplePurchases: SKProductsRequestDelegate {

public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
let products = response.products
/// Do something with the products
}

public func request(_ request: SKRequest, didFailWithError error: Error) {
/// Do something with the error
}
}

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:

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

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?

Sign Up