In-App Products Module for iOS

API Docs for: 1.0.2
Show:

Readme

Introduction

This module allows the Titanium developer to provide in-app products.

Usage

Note: This module provides functionality that will not work in the simulator. Please run your tests on an actual device.

This module provides access to the products defined in iTunes Connect. You will need to add your app to iTunes Connect and define the in-app products there.

The following code segments are not complete; they only demonstrate the essentials of using the module. See example/app.js for a complete example.

You load the module as usual:

var InAppProducts = require('com.logicallabs.inappproducts');

Basic steps to get a list of available products:

InAppProducts.addEventListener('receivedProducts', function(e) {
    e.products.forEach(...
});

if (InAppProducts.getProducts({ SKUs: productIDs })) {
    Ti.API.info('getProducts request started successfully.');
} else {
    alert('Error: could not start getProducts request!');
}

Basic steps to purchase a product:

InAppProducts.addEventListener('purchaseUpdate', function(e) {
   switch (e.purchase.state) {
        ...
});
productObj.purchase();

Completing a Purchase

The purchase process of in-app products on iOS separates the steps of completing the payment and completing the purchase itself. When the payment for the product is received, the related Purchase object goes into PURCHASE_STATE_PURCHASED state. This signals to the app that the purchased functionality should be made available to the user in the app's environment.

Once the app completed the processing of a purchase, it must call the complete method. If the app fails to do this, perhaps because it is terminated before it can completely process the purchase, it will receive a purchaseUpdate event for the uncompleted purchase the next time it starts up. The module will cache these events until the purchaseUpdate event handler becomes available and then deliver all the outstanding events at once. For this reason it is important to prepare this event handler for handling such seemingly unsolicited events.

Issues and Limitations

Web receipt verification with the iTunes Store is not part of the module at this time -- the best practice encouraged by Apple is to perform this verification on an independent server, not on the device.

Change Log

Version 1.0.0

  • First release

Version 1.0.2

  • Documentation fixes.

Author

Zsombor Papp, Logical Labs titanium@logicallabs.com

License

See LICENSE file included with the module for all terms and conditions specific to this module.

General terms and conditions for all Logical Labs Titanium Modules can be found here: http://www.logicallabs.com/logical-labs-titanium-module-terms-conditions

Copyright (c) 2013-2014 by Logical Labs, LLC