A simple helper for in app purchases.
By default it will load product information from the plist InAppPurchases.plist.
Example Plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Name</key>
<string>MoreCoins</string>
<key>Title</key>
<string>More Coins</string>
<key>ProductId</key>
<string>com.myapp.MoreCoins</string>
<key>Type</key>
<string>Consumable</string>
</dict>
<dict>
<key>Name</key>
<string>RemoveAds</string>
<key>Title</key>
<string>Remove Ads</string>
<key>ProductId</key>
<string>com.myapp.RemoveAds</string>
<key>Type</key>
<string>Non-Consumable</string>
</dict>
</array>
</plist>
You can override product information with:
[[IAPHelper defaultHelper] setProductInfo:myProducts];
Use these methods:
- (NSArray *) productIdsByNames:(NSArray *) productNames;
- (NSString *) productIdByName:(NSString *) productName;
- (NSString *) productTypeForProductId:(NSString *) productId;
- (NSString *) productNameByProductId:(NSString *) productId;
- (NSString *) productTitleForProductId:(NSString *) productId;
- (NSString *) productDescriptionForProductId:(NSString *) productId;
Loaded products from itunes are stored internally for you.
- (void) loadItunesProductId:(NSString *) productId withCompletion:(IAPHelperLoadProductsCompletion) completion;
- (void) loadItunesProductNamed:(NSString *) productName withCompletion:(IAPHelperLoadProductsCompletion) completion;
- (void) loadItunesProductsWithNames:(NSArray *) productNames withCompletion:(IAPHelperLoadProductsCompletion) completion;
- (void) loadItunesProducts:(NSArray *) productIds withCompletion:(IAPHelperLoadProductsCompletion) completion;
- (void) restorePurchasesWithCompletion:(IAPHelperRestorePurchasesCompletion) completion;
- (void) purchaseItunesProductNamed:(NSString *) name completion:(IAPHelperPurchaseProductCompletion) completion;
- (void) purchaseItunesProductId:(NSString *) productId completion:(IAPHelperPurchaseProductCompletion) completion;
- (void) purchaseItunesProductId:(NSString *) productId quantity:(NSInteger) quantity completion:(IAPHelperPurchaseProductCompletion) completion;
SKProducts are available after you load then from itunes
- (SKProduct *) productForItunesProductId:(NSString *) productId;
- (SKProduct *) productForName:(NSString *) name;
This will only work for Non-Consumable products.
- (BOOL) hasPurchasedNonConsumableNamed:(NSString *) productNameInPlist;
- (NSString *) currencyCode;
- (NSNumber *) priceForItunesProductId:(NSString *) productId;
- (NSString *) priceStringForItunesProductId:(NSString *) productId;
- (NSString *) priceStringForItunesProductNamed:(NSString *) name;
//when product load from itunes completes.
typedef void(^IAPHelperLoadProductsCompletion)(NSError * error);
//when a purchase completes.
typedef void(^IAPHelperPurchaseProductCompletion)(NSError * error, SKPaymentTransaction * transaction);
//called for each product that is restored.
//When all restores are completed the 'completed' flag is TRUE.
typedef void(^IAPHelperRestorePurchasesCompletion)(NSError * error, SKPaymentTransaction * transaction, BOOL completed);