VSStoreKit is an easy to use library that you can use to make in-app purchases in your iOS app.
- Swift 5.0
- Xcode 10
- iOS 8.0+
CocoaPods (recommended)
use_frameworks!
pod 'VSStoreKit'
Read the docs. Generated with jazzy. Hosted by GitHub Pages.
$ ./build_docs.sh
$ open index.html -a Safari
import VSStoreKit
This library has five primary components with the following responsibilities:
StoreAccess
— requesting products from the Store, providing product details such as price and purchasing productsPurchasedProductsProtocol
— instance conforming to this protocol stores completed purchasesLocalProductsDataSource
— instance conforming to this protocol provides information about products for sale in the appProductsDataSource
— also provides information about products for sale, but combines local and received from the Store information about productsStoreAccessObserver
— observing StoreAccess state change and notifying client via callback methods
// 1. Create an instance conforming to PurchasedProductsProtocol
let puchasedProducts: PurchasedProductsProtocol = PurchasedProducts()
// 2. Provide StoreAccess purchaseCompletionHandler so it can mark products as purchased
let storeAccess = StoreAccess.shared
storeAccess.purchaseCompletionHandler = { purchasedProductIdentifier in
puchasedProducts.markProductAsPurchased(purchasedProductIdentifier)
}
// 3. Create an instance conforming to LocalProductsDataSource with your products (in-app purchases)
let localProducts: LocalProductsDataSource = LocalProducts()
// 4. Request products from the store
storeAccess.requestProductsWithIdentifiers(localProducts.productIdentifiers)
// 5. Instantiate ProductsDataSource object that you will use to populate your UITableView, UICollectionView or whatever with products (in-app purchases)
let productsDataSource = ProductsDataSource(localProducts: localProducts, storeProducts: storeAccess)
// 6. Buy product
let productIdentifier = productsDataSource.identifierForProductAtIndex(index)
storeAccess.purchaseProductWithIdentifier(productIdentifier)
// 7. Observe StoreAccess state change with help of StoreAccessObserver by providing it optional handlers for the states you are interested in
let storeAccessObserver = StoreAccessObserver()
storeAccessObserver.receivedProductsStateHandler = {
// reload your products presentation
}
storeAccessObserver.purchasedStateHandler = {
// reload your products presentation
}
Vladimir Shutyuk, vladimir.shutyuk@gmail.com
VSStoreKit is available under the MIT license. See the LICENSE file for more info.