To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS 9 or Higher
- Swift 5.0
AwesomePurchase is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "AwesomePurchase", git: 'https://github.com/iOSWizards/AwesomePurchase', tag: '0.1.6'
AwesomePurchase.start(with: ["identifier1", "identifier2", ...])
Test Environment
AwesomePurchase.start(with: ["identifier1", "identifier2", ...], isProduction: false)
Single Product
AwesomePurchase.shared.product(withIdentifier: "PRODUCT IDENTIFIER") { (product, message) in
// any further action
}
All Available Products
AwesomePurchase.shared.products { (success, products, message) in
// any further action
}
AwesomePurchase.shared.purchaseProduct(withIdentifier: "PRODUCT IDENTIFIER") { (success, receipt, message) in
// any further action
}
In order to make the usability for Subscription simpler, you can take advantage of the Subscription Protocol. Ideally, you should create a helper class to handle the subscription and be responsible for any change in the subscripton state.
Here's an example of the implementation:
import AwesomePurchase
import StoreKit
enum SubscriptionId: String {
case monthly = "IDENTIFIER 1"
case yearly = "IDENTIFIER 2"
}
class AwesomePurchaseHelper: AwesomePurchaseSubscriptionProtocol {
static var shared = AwesomePurchaseHelper()
var products: [SKProduct] = []
var iapHelper: AwesomePurchaseStore?
var appStoreSecret: String {
return "yourAppStoreSecret"
}
static func start() {
AwesomePurchase.start(with: [SubscriptionId.monthly.rawValue, SubscriptionId.yearly.rawValue], isProduction: false)
shared.addPurchaseObservers()
shared.updateProducts { (products) in
shared.products = products
}
}
func receiptConfirmed(isValid: Bool) {
// take action
}
}
In order to update your view according to Subscription status update, implement the AwesomePurchaseSubscriptionStatusProtocol
.
extension YourView: AwesomePurchaseSubscriptionStatusProtocol {
func updatedSubscriptionStatus() {
// update UI
}
}
AwesomePurchase is available under the MIT license. See the LICENSE file for more info.