Giter Club home page Giter Club logo

iapmanager's Introduction

IAPManager

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.

Features

  • Simple setup
  • Efficient one-line check if a product was purchased
  • SKProducts to obtain prices
  • Restoring purchases
  • Uses block for callbacks

Requirements

iOS 5 or above with ARC and StoreKit.framework.

How-to

  1. Create your purchases in iTunes Connect. For details see the In-App Purchase Programming Guide.
  2. Add StoreKit.framework to your project
  3. Add IAPManager.h and IAPManager.m into your project, or use the Pod IAPManager.
  4. Create your IAP UI
  5. Use the methods of the [IAPManager sharedIAPManager] singleton:
    • Check if the App Store is available: [[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:extrasPackProduct.priceLocale];
                                              NSString *formattedPrice = [numberFormatter stringFromNumber:premium.price];
                                              NSLog(@"super premium: %@ for %@", premium.localizedTitle, formattedPrice);
                                          }
}];
- To purchase a product:
[[IAPManager sharedIAPManager] purchaseProductForId:@"superpremiumversion"
                                         completion:^{
                                             [[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.

Contact

Travis CI build status

Bug reports and pull requests are welcome! Contact me via e-mail or just by opening an issue on GitHub.

iapmanager's People

Contributors

iamamused avatar siuying avatar stefanmunz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.