Allowing Multiple Purchases
Currently, the user interface only allows you to purchase the consumable purchase once. Obviously that defeats the point, so let's fix this.
Open RageProducts.swift and add the following method:
public static func isProductPurchased(_ productIdentifier: ProductIdentifier) -> Bool {
if (productIdentifier == RageProducts.RandomRageFace) {
return false
} else {
return RageProducts.store.isProductPurchased(productIdentifier)
}
}
This checks to see if the product identifier is consumable, and if so always marks it as available for purchase.
Next open ProductCell.swift and inside product
's didSet
, find this line:
if RageProducts.store.isProductPurchased(product.productIdentifier) {
and replace that with the following:
if RageProducts.isProductPurchased(product.productIdentifier) {
Build and run, and you should now be able to purchase all the random rage faces you want!
Where To Go From Here?
Here is the final sample project from the In App Purchases tutorial series.
Congrats - you now have implemented both non-consumable and consumable In-App Purchases, and added the ability for users to restore transactions!
This In App Purchases tutorial may provide more than enough functionality for simple apps. But if you want to take things even further and learn how develop a robust and extensible app, check out In-App Purchase Video Tutorial Series!
I hope you enjoyed this In App Purchases tutorial, and wish you best of luck with your consumable In-App Purchases! Just don't be too sneaky or evil, one Zynga is enough ;]