Yet Another simple in-app purchase interface for iOS.
A simple toolkit for non-renewables (a.k.a "Premium Features") with In-App Purchase. The main goal is ease of use. Therefore, more complicated parts, like checking of receipts, are not provided.
iOS 5 or above with ARC and StoreKit.framework.
IAPManager.h
and IAPManager.m
into your project, or use the Pod IAPManager
.Use the methods of the [IAPManager sharedIAPManager]
singleton:
[[IAPManager sharedIAPManager] canPurchase]
To obtain product information:
[[IAPManager sharedIAPManager] getProductsForIds:@[@"superpremiumversion"]
completion:^(NSArray *products) {
BOOL hasProducts = [products count] != 0;
if(! hasProducts) {
NSLog(@":(");
}
else {
SKProduct *premium = products[0];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:premium.priceLocale];
NSString *formattedPrice = [numberFormatter stringFromNumber:premium.price];
NSLog(@"super premium: %@ for %@", premium.localizedTitle, formattedPrice);
}
}];
To purchase a product:
[[IAPManager sharedIAPManager] purchaseProductForId:@"superpremiumversion"
completion:^(SKPaymentTransaction *transaction) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIAlertView *thanks = [[UIAlertView alloc] initWithTitle:@"Thanks!"
message:@"The extra features are now available"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[thanks show];
} error:^(NSError *err) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(@"An error occured while purchasing: %@", err.localizedDescription);
// show an error alert to the user.
}];
StoreKit will then ask the user if they want to purchase the product.
Bug reports and pull requests are welcome! Contact me via e-mail or just by opening an issue on GitHub.