Search code examples
titaniumappceleratortitanium-mobileappcelerator-titaniumappcelerator-mobile

In App purchase for iOS (Appcelerator)


I want to add in-app purchase functionality for iOS but I can't make it working.

I tried to use ti.storekit, but when I initialize it I get error that addTransactionObserver is undefined and this is crucial function on initialization.

Does anyone have luck with it?

My code:

var storekit = require('ti.storekit');
var transactionStateChanged = function(e) {
    alert(e)
}


function init() {
    storekit.receiptVerificationSandbox = Ti.App.deployType !== 'production';
    storekit.bundleVersion = '1.0.4';
    storekit.bundleIdentifier = 'pl.aplikacjanowa';
    storekit.addEventListener('transactionState', transactionStateChanged);
    storekit.addTransactionObserver();
}

init();

Error:

[INFO] :   [object TiStorekitModule] loaded
[ERROR] :  Script Error {
[ERROR] :      column = 37;
[ERROR] :      line = 598;
[ERROR] :      message = "undefined is not a function (evaluating 'storekit.addTransactionObserver()')";
[ERROR] :      sourceURL = "file:///xyz"; //instead of xyz is path to file in which that function invoked
[ERROR] :      stack = "init@file:///xyz"; //instead of xyz is path to file in which that function invoked
[ERROR] :  }

Solution

  • It seems you initially used outdated version of the module or incorrectly compiled it.

    As you mention in your comment something did go wrong with compiling I'm assuming that is the issue. A good description how to implement the module is on Medium, and releases are available for download from the Appcelerator GitHub. Don't trust on Gitt.io from always having the latest.