iOS In-App Purchases

The InAppPurchases class lets you sell a variety of items directly within your free or paid app, including premium content, virtual goods, and subscriptions. This package includes full source code, a working demo, a test user and products. View Pricing
scroll down for more

The InAppPurchases class is used to easily add any number of In-App purchases to any app and allow users to purchase or restore purchases at any time. Add another source of revenue to your app by adding add-ons as In-App purchases.

InAppPurchases lets you sell a variety of items directly within your free or paid app, including premium content, virtual goods, and subscriptions. And just like apps you sell on the App Store, you receive 70% of the purchase price

InAppPurchases lets you sell a variety of items directly within your free or paid app, including premium content, virtual goods, and subscriptions.

For example, InAppPurchases will allow you to sell:

  • Digital books or photos
  • Additional game levels
  • Access to a turn-by-turn map service
  • Subscriptions to digital magazines or newsletters
  • Digital content hosted on Apple servers

Your app will be able to:

  • Connect to the app store's in app purchase service
  • Purchase products
  • Automatically manages already purchased products
  • Restore purchases (required by Apple AppStore for all apps providing In-App Purchases)
  • Acquire product details
  • Determine already purchased products
  • Determine if can make payments
  • Determine is a product is valid.
  • Get a valid products identifier, localized description, localized title, localized price, and price.
  • Use In-App purchase menu popover for initiating In-App purchases or roll your own.
  • Full tracking of request, purchase and restore process so can fully integrate with your app.

Test User and Products

A test user and products come with the demo so actually purchases and restores can be done.

InAppPurchases in iTunes Connect

Includes step by step instructions for setting up your app's In-App purchase in iTunes Connect.

iOS Support

This project supports iOS 7, iOS 8, iOS 9 and iOS 10.

Pricing

14 day 14-day money-back guarantee

$19.99

Single App

  • Perpetual license

  • 1 application

  • Can distribute binary products only

  • Commercial use

  • 1 month support

$49.99

Developer

  • Perpetual license

  • Unlimited projects

  • Can distribute code and binary products

  • Commercial use

  • 12 months support

Supported OS & SDK Versions

  • Supported build target - iOS 7.0, iOS 8.0,  iOS 9.0 and iOS 10 / Mac OS 10.7 (Xcode 4.3.1, Apple LLVM compiler 3.1)
  • Earliest supported deployment target - iOS 6.1 / Mac OS 10.6
  • Earliest compatible deployment target - iOS 6.1 / Mac OS 10.6

NOTE: 'Supported' means that the library has been tested with this version. 'Compatible' means that the library should work on this OS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly.

Installation

To install InAppPurchases into your app, drag the contents of the InAppPurchases folyer into your project. Make sure that you indicate to copy the files into your project. Also make sure that the Target Membership is checked so is included in your project.

All main methods provided are class static methods and are called by using [InAppPurchases initWithProductIdentifiers …] or [InAppPurchases initWithProductIdentifier];

Use the static methods to create one or more InAppPurchase objects then uses the InAppPurchase objects methods.

Usage

// see Demo Example in Examples/Demo folder for full source code

// array of product identifiers for your products...
//    
NSArray * productIdentifiers = [[NSArray alloc] initWithObjects:@"com.markelsoft.InAppPurchases.productone", @"com.markelsoft.InAppPurchases.producttwo", nil];

//      (see InAppPurchase.h definition of the delegate InAppPurchaseDelegate)
//
// provide array of product identifiers for your products...
// delegate is yourself so you can track requests, errors, purchases or restores (see below)
//
// returns an array of InAppPurchase objects.
//
NSMutableArray * inAppPurchases = [InAppPurchase initWithProductIdentifiers:productIdentifiers delegate:self];

// can also setup one In-App purchase at a time if like
// uncomment to use
//
// returns a InAppPurchase object.
//
//InAppPurchase * inAppPurchase = [InAppPurchase initWithProductIdentifies:@"com.markelsoft.InAppPurchases.productone" delegate:self];

if (inAppPurchases != nil) {
    NSLog(@"created %d in-app-purchase objects...", inAppPurchases.count);

    inAppPurchase_ProductOne = [inAppPurchases objectAtIndex:0];

    // verbose debug mode        
    [inAppPurchase_ProductOne setVerbose:FALSE];
    //[inAppPurchase_ProductOne clearUserDefaultsSetting];  // for testing to reset purchase.  run once with uncommented and restart with commented out

    msg = [NSString stringWithFormat:@"Product One productId: %@", inAppPurchase_ProductOne.productId];
    NSLog(@"%@", msg);

    inAppPurchase_ProductTwo = [inAppPurchases objectAtIndex:1];

    // verbose debug mode        
    [inAppPurchase_ProductTwo setVerbose:FALSE];
    //[inAppPurchase_ProductTwo clearUserDefaultsSetting];   // for testing to reset purchase.  run once with uncommented and restart with commented out

    msg = [NSString stringWithFormat:@"Product Two productId %@", inAppPurchase_ProductTwo.productId];
    NSLog(@"%@", msg);

} else {
    msg = @"Error creating in-app purchases objects!";
    [self setStatus:msg];
}


// InAppPurchase callbacks (see InAppPurchaseDelegate)

// called when product is validated so products details returned….
- (void)requestedProduct:(InAppPurchase *)iap identifier:(NSString*)productId name:(NSString*)productName price:(NSString*)productPrice description:(NSString*)productDescription {

      // see the full demo
      // check is ipa == inAppPurchase_ProductOne or pa == inAppPurchase_ProductTwo to determine which product is for.
      // do same for all other callbacks providing iap InAppPurchase object.
}

// called when a product is purchased or a purchase restored...
- (void)successfulPurchase:(InAppPurchase*)iap restored:(bool)isRestore identifier:(NSString*)productId receipt:(NSData*)transactionReceipt {

}

// called when a product purchases fails...
- (void)failedPurchase:(InAppPurchase*)iap error:(NSInteger)errorCode message:(NSString*)errorMessage {

}

// called when an incomplete restore of a purchase has occurred...
- (void)incompleteRestore:(InAppPurchase*)iap {

}

// called wen a restore of a purchase has failed...
- (void)failedRestore:(InAppPurchase*)iap error:(NSInteger)errorCode message:(NSString*)errorMessage {

}

// end of InAppPurchase callbacks

// See 'Methods' section for full details on InAppPurchase static and instance methods.    

Example Project Demo

The demo example in the Examples/Demo folder demonstrates how you might implement using InAppPurchases. When run, the app runs through an example in-app purchase. Sign out of the iTunes Store before testing the demo app as you will need to use the following Test user credentials to login and buy using the sandbox.

For this demo to work you should log out of your iTunes Store account and when prompted, must login into the iTunes Store test user credentials below.

You should go into iTunes Connect and create you own test user account for your In-App purchase testing.

Test user credentials: email: inapppurchasesdemo@markelsoft.com password: Inappdemo11

Using code in your app:

In your product code change the product identifiers to the identifiers for your product.

The demo code provides product identifiers that work when used with the provided test account.

The example is for iOS.

Methods

// Static Methods:

// for multiple purchases...
//
// providing an array of product Ids (e.g. com.markelsoft.PepprGallery.effects).  Setup in iTunes Connect for app.
// delegate - delegate to receive callbacks for in-app-purchase events
//
// returns an array of InAppPurchase objects
//
+ (NSMutableArray *)initWithProductIdentifiers:(NSArray *)productIdentifiers delegate:(id<InAppPurchaseDelegate>) delegate;

// for a single purchase...
//
// providing a single product Id. (e.g. com.markelsoft.PepprGallery.effects).  Setup in iTunes Connect for app.
// delegate - delegate to receive callbacks for in-app-purchase events
//
// returns an InAppPurchase object
//
+ (InAppPurchase *)initWithProductIdentifier:(NSString *)productIdentifiers delegate:(id<InAppPurchaseDelegate>) delegate;

// show purchase popover
//
// purchases - an array contains InAppPurchase objects
// point - point to show popover at in specified view (inView)
// view - view to show popover in
// title - title of popover menu
// includeRestore - add 'Restore Purchases' menu to end of popover menu.
//                  A good idea since restore is required by Apple AppStore.
// delegate - delegate to receive callbacks when select a menu entry or popover is dismissed
//
// returns InAppPopoverView
//
+ (InAppPopoverView *)showPurchasePopover:(NSArray *)purchases atPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title includeRestore:(BOOL)includeRestore delegate:(id<InAppPopoverViewDelegate>)delegate;


//InAppPurchase Methods:

- (BOOL)canMakePayments;     // determines if can make payments.  TRUE - yes, FALSE - NO
- (BOOL)purchaseProduct;     // called to purchase the product.  TRUE - yes, FALSE - NO
- (BOOL)restorePurchase;     // called to restore the purchase of the product.  TRUE - yes, FALSE - NO
- (BOOL)alreadyPurchased;    // indicates if was already purchased.  TRUE - yes, FALSE - NO
- (BOOL)isPurchased;         // indicates if was purchased.  TRUE - yes, FALSE - NO
- (BOOL)isRestored;          // indicates if purchase was restored.  TRUE - yes, FALSE - NO
- (BOOL)isValidProduct;      // determines if is a valid product.  TRUE - yes, FALSE - NO.   A product becomes valid when the iTunes App Store returns details indicating the product id is a valid product
- (NSString *)getProductId;  // get product Id regardless of whether validated or not
- (SKProduct *)getValidProduct;   // get valid product object.
- (NSString *)getValidProductId;  // get valid product Id
- (NSString *)getValidProductLocalizedDescription;  // get the valid product description localized
- (NSString *)getValidProductLocalizedTitle;        // get the valid product title localized
- (NSString *)getValidProductLocalizedPrice;        // get the valid product price localized

- (void)clearUserDefaultsSetting;  // clear settings such as already previous purchase from user defaults
- (void)setVerbose:(BOOL)verbose;  // turn verbose mode on or off.  Used for debugging.
// end of instance methods

// local methods...
- (BOOL)requestProduct:(NSString *)productId;
- (BOOL)purchaseProduct:(SKProduct*)requestedProduct;

Setting up In-App Purchases in iTunes Connect

To create your own In-App purchases for a product go into iTunes Connect 'Manage Your Applications' and select your app.

Next click 'Manage In-App Purchases'.

In here you will create each of your In-App purchases you want available for the app. Be sure to use your apps Bundle Identifier e.g. for this demo app com.markelsoft. InAppPurchasesDemo. So for a new in-app purchases for a network tool might use 'com.yourcompany.yourproduct.inapppurchase' e.g in the demo provided: 'com.markelsoft.InAppPurchases.productone' and 'com.markelsoft.InAppPurchases.producttwo'.

Selecting created In-App purchases in App Details:

Also be sure once you create the In-App purchases that you go into your App Details 'In-App Purchases' section and add the In-App purchases before (very key) the app binary is submitted. Once the app binary is submitted, iTunes Connect looks for In-App purchases that are ready.

Markelsoft Apps using iOS InAppPurchases

  • PepprGallery - http://itunes.com/apps/pepprgallery
  • iMySystem - http://itunes.com/apps/imysystem