Local Receipt Validation in Swift 3


When using StoreKit, there are two ways to validate a receipt. One is to validate with the App Store. It’s recommended if you are doing it from a trusted server. The procedure is straightforward and easy to implement. However, if you want to validate a receipt from the device directly, while “a trusted connection between a user’s device and the App Store directly” is not possible as stated by Apple, you’d better to choose the other way, which is to validate the receipt locally.

The local validation is not as easy as to validate with the App Store service. Meanwhile, Apple believe the approach should not base on the same implementation due to security consideration and doesn’t provided a complete sample code for you to copy and paste, which makes it even harder. objc.io had a wonderful article on how to do it in Objective-C. There are also some articles about how to do it in Swift but are either incomplete or obsolete somehow.

In this series, I kept a record on how I made it for iOS in Swift 3.

The implementation is under Xcode 8 with iOS 10 SDK. The ultimate document from Apple about the this can be found at General->Guides->Receipt Validation Programming Guide. I won’t leave a link here since it changes all the time. Just check it out in Xcode.

  1. Preparation
  2. Validation