Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

StoreKit Module crashing constantly

Is anyone else experiencing constant crashing from the StoreKit Module? I am getting "SKProductsRequest handleFinishResponse:returningError" in the crash logs.

The issue is intermittent. Sometimes I get a valid product array (so I know my app, products, and provisioning profile are all setup correctly), other times it just crashes right after the app opens. It seems like a timing issue.

To duplicate the issue, you can use the following code (you will need a valid app id with app store products and the corresponding provisioning profile).

My environment is as follows: iPhone 4, iOS SDK 4.3, Titanium Studio 1.0.4, Mobile SDK 1.7.2, Mac OS X 10.6.8, Apple StoreKit Module 1.1

Here is my crash log: https://gist.github.com/1171984

add this to tiapp.xml:

<modules>
  <module version="1.1">ti.storekit</module>
</modules>

app.js

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// In-App purchases
Titanium.Storekit = Ti.Storekit = require('ti.storekit');
var storeProducts = [];

function createWindow (_args) {
    var win = Ti.UI.createWindow(_args);
    return win;
}

var win1 = createWindow({title:'Window 1'});
var tab1 = Titanium.UI.createTab({
    title:'Tab 1',
    window:win1
});

var win2 = createWindow({title:'Window 2'});
var tab2 = Titanium.UI.createTab({
    title:'Tab 2',
    window:win2
});

var tabgroup = Titanium.UI.createTabGroup();
tabgroup.addTab(tab1);
tabgroup.addTab(tab2);

tabgroup.open();

getStoreProducts = function(_args) {
    if (_args===undefined) {_args={};};
    storeProducts = []; // reset products array
    if (!Ti.Storekit.canMakePayments) {
        Ti.API.info("Can NOT make payments to in-app purchase store");
        if (_args.error) {
            _args.error({error:"Cannot make payments to in-app purchase store"});
        };
        Ti.UI.createAlertDialog({
            title:'Error',
            message:'Cannot make payments to in-app purchase store'
        }).show();
    } else {
        try {
            Ti.Storekit.requestProducts(['com.example.myapp.testProduct01'], function(e) {
                if (!e.success) {
                    Ti.API.info("Could not get products: " + JSON.stringify(e));
                    if (_args.error) {
                        _args.error(e);
                    };
                } else {
                    storeProducts = e.products;
                    Ti.App.fireEvent('app:store.hasProducts');
                    if (_args.success) {
                        _args.success(e);
                    };
                }
            });
        } catch (e) {
            Ti.API.info("Ti.Storekit.requestProducts EXCEPTION: " + JSON.stringify(e));
        }
    } // END if (!Ti.Storekit.canMakePayments)
};

win1.addEventListener('focus', function(e) {
    Ti.API.info("Getting store products...");
    getStoreProducts({
        error: function(e) {
            Ti.API.info("getStoreProducts ERROR: " + JSON.stringify(e));
        },
        success: function(json) {
            Ti.API.info("getStoreProducts SUCCESS: " + JSON.stringify(json));
        }
    });
    Ti.API.info("Simulating some data processing...");
    setTimeout(function() {
        Ti.API.info("DONE loading data...");
    }, 8000);
});
win2.addEventListener('focus', function(e) {
    Ti.API.info("Getting store products...");
    getStoreProducts({
        error: function(e) {
            Ti.API.info("getStoreProducts ERROR: " + JSON.stringify(e));
        },
        success: function(json) {
            Ti.API.info("getStoreProducts SUCCESS: " + JSON.stringify(json));
        }
    });
    Ti.API.info("Simulating some data processing...");
    setTimeout(function() {
        Ti.API.info("DONE loading data...");
    }, 8000);
});
— asked August 25th 2011 by David Knell
  • crash
  • iphone
  • mobile
  • storekit
  • titanium
4 Comments
  • I added a community bug report to track this issue. My app was just approved in the app store and I'm hoping someone has some insight into these crashes. Thanks!

    — commented August 25th 2011 by David Knell
  • Here's the ticket I opened - http://jira.appcelerator.org/browse/TC-230

    — commented August 25th 2011 by David Knell
  • So for your product ID, is it the in-app ID you make, or is it the app id for that app or what? Appcelerator folks are dropping the ball by not answering…

    Also, is your product 'Waiting for Review'? I have one ready in an update, but I get an error in XCODE when its trying to get the products, saying invalid object or something. It's getting to the 'success' part though

    — commented October 5th 2011 by Josh Lewis
  • Josh,
    I was having a lot of problems getting the StoreKit to work also. Eventually I came across the following blog posts that had a lot of good tips (especially the comments).

    http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/
    http://troybrant.net/blog/2010/01/invalid-product-ids/comment-page-1

    As for the product ID, you set that up in the In-App Purchases section of iTunes Connect (see screenshot below). The product id's you pass to Ti.Storekit.requestProducts has to be EXACTLY what you created in iTunes Connect. Also another thing that got me was that Ti.Storekit.requestProducts returns a JSON result (in my example above - e), and I was trying to do something like:

    Ti.API.info(e.products[0]);
    

    but that doesn't work because those are Ti.Storekit.Product objects. You have to debug a property of that object:

    Ti.API.info(e.products[0].title);
    

    Product ID in iTunes Connect

    I hope that helps!

    Dave

    — commented October 6th 2011 by David Knell

0 Answers

The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.