InAppPurchase is an open source Swift library submitted by Jin Sasaki providing a simple syntax for In-App purchases with support for iOS 11’s new features for promoting in-app purchases.
This snippet from the readme shows the syntax for handling an in-app purchase with Store Kit:
let iap = InAppPurchase.default
iap.purchase(productIdentifier: "PRODUCT_ID", finishDeferredTransactionHandler: { (result) in
// `finishDeferredTransactionHandler` is called if the payment had been deferred and then approved.
// For example, the case that a child requests to purchase, and then the parent approves.
switch result {
case .success(let state):
// Handle `InAppPurchase.PaymentState` if needed
case .failure(let error):
// Handle `InAppPurchase.Error` if needed
}
}, handler: { (result) in
// This handler is called if the payment purchased, restored, deferred or failed.
switch result {
case .success(let state):
// Handle `InAppPurchase.PaymentState`
case .failure(let error):
// Handle `InAppPurchase.Error`
}
})
You can find InAppPurchase on Github here.
A nice simple to use library for working with StoreKit.
Original article: InAppPurchase – A Simple Swift Library For In-App Purchases With Support For iOS 11’s Promotion Features
©2017 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.