StoreKit Testing in Xcode 12: Getting Started | raywenderlich.com

Learn to use the new StoreKit testing framework to exercise your in-app purchases right inside Xcode.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/15410082-storekit-testing-in-xcode-12-getting-started

I have really enjoyed reading this tutorial and I plan to add StoreKit Tests to my project. (finally I can test this without real device :slight_smile: )

first of all, I would like to ask a question about OpenSSL library that was used in the tutorial. Are there any frameworks made by apple that allows safe SSL connection? Secondly, could you provide more informations about cryptographic techniques that were used in this project? (Looks like ASN1Helpers.swift file is used for reading decoded data)

1 Like

@isam can you please have a look at this?

1 Like

@bartozo thank you for the feedback. I’m glad you like! :smiley:

Apple’s URLSession supports HTTPS connections and as far as I know, it supports using client certificates if you want to use custom certificates. There are also CommonCrypto and CryptoKit for advanced cryptography uses.

In this tutorial OpenSSL is used to help in verifying the cryptography and to decode the ASN.1 data of the IAP receipt, that’s in PKCS #7 format. Receipts in sandbox environment are signed by Apple’s root certificate, while in Xcode they are signed by a local certificate.
Check out this great article by Bill Morefield about In-App Purchases: Receipt Validation Tutorial | raywenderlich.com. It explains the details of validating and decoding receipts and how they’re signed. In fact, I’ve used the same validation and decoding code.

Hope this helps!

This has been a great tutorial to understand the Storekit testing. Thank you :slight_smile:

I have added the Storekit testing to my existing project and it works as expected. But for unit test cases, I referred your “testSubscription()” method where in you are calling “session.expireSubscription” to expire the existing subscription (step number 5). Looks like the expireSubscription is not working. It fails in your tutorial sample application as well. can you please help me with a solution.

1 Like

@pavanakc Thank you for the feedback! I’m glad to know it helped :blush:
Please let me know what iOS version you’re using to test.

When I worked on the tutorial, I tested expireSubscription(productIdentifier:) on all iOS 14 releases. Back then, it only worked on devices and simulators running iOS 14.1.
In 14.2, 14.3 and 14.4, it seems to be broken.

The subscriptionExpirationDate property doesn’t get updated in the local receipt after calling expireSubscription(productIdentifier:) and that causes the test to fail. I filed a radar about it.

I tested it on iOS 14.5 and 14.6 and it worked as expected. Please let me know if it’s works on these iOS versions. I will update the tutorial accordingly.

@isam Thank you for the support :slight_smile: . Yes you are right, I was testing it on iOS 14.4 simulator and hence it was failing. Also, it works as expected on iOS 14.5 and 14.6…

Also, can you please help me understand if there is any OpenSSL pod which can be used for the local receipt validation. (Wanted to reduce the number of files used in the application)
I tried using pod - OpenSSL-Universal, but receipt validation seems to fails. Are there any difference wrt OpenSSL used in this tutorial and the pod version ?