Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Patrick

After 2 weeks of trial and error, I finally get the iAP working. I hit a lot of problems so I want people to avoid repeating my stupid mistakes. I am a 46-year-old programmer and I found myself getting a bit slow in everything. I believe you are all better than me, but I hope these should still help to save your precious time a bit. Here we go:

HOW TO MAKE IAP WORKING?

1. Please ensure your BUILD TARGET IOS version is iOS 6.1.
I made a big mistake and got unknown error if I put iOS 5.1

2. Please ensure you TEST your app on a REAL iPhone or iPad, not Simulator.
I spent lot of time troubleshooting but found out that IAP is not supported on iOS Simulator (the information I surfed, correct me if I am wrong)

3. On your TEST machine, ensure your own App Store account is LOGOUT! Otheriwse you will hit another strange error for no reason. Once you logout your own App Store account, you can use the IAP test account.

4. Do not put the IAP codes inside Class because it will crash. (sorry, I am not sure I am technically correct, Dom please correct me if I am wrong. ) I put the codes (basically a copy-and-change from the Ejecta IAP example) in another file, and include it in index.js.

5. As the IAP codes seem do not block, so I use some signal variables to check it status. Well, I think there could be better way to do it. Tell me and thanks a lot.

Here are my codes:

index.js
=============================
jecta.include('lib/game/iap.js');
// Load the game
ejecta.include('lib/impact/impact.js');
ejecta.include('lib/game/main.js');

iap.js
==============================
//
// iap.js - In-App Purchase functions
//
var iap = new Ejecta.IAPManager();

// these variables are only used by iapPurchase, do not write to them, read-only by external codes
var iapPurchaseStarted = false;
var iapPurchaseCompleted = false;
var iapPurchaseSuccess = false;

function iapPurchase( productId )
{
if (iapPurchaseStarted == true)
return;

// initialize the signal variables
iapPurchaseStarted = true;
iapPurchaseCompleted = false;
iapPurchaseSuccess = false;

iap.getProducts( [productId], function(error, products)
{
if( error )
{
console.log( error );
iapPurchaseCompleted = true;
iapPurchaseSuccess = false;
}
else
{
var selectedProduct = null;
for( var i = 0; i < products.length; i++ )
{
console.log(
products[i].id,
products[i].title,
products[i].description,
products[i].price
);

if( products[i].id == productId )
{
selectedProduct = products[i];
}
}

selectedProduct.purchase(1, function(error, transaction)
{
if( error )
{
console.log(error);
iapPurchaseCompleted = true;
iapPurchaseSuccess = false;
}
else
{
// Purchase successful; log some transaction info
console.log(
transaction.productId,
transaction.id,
transaction.receipt
);
iapPurchaseCompleted = true;
iapPurchaseSuccess = true;
}
});
}
});

iapPurchaseStarted = false;
}

main.js
=============================

Inside the main.js, I put the call iapPurchase( p ) inside a state machine of update() block, and make sure it will not be called twice once the user hit the buy button. Then the code will keep watching the signal variables until the iapPurhcaseComplete becomes true. Then the codes will check if iapPurchaseSuccess is true or not and then take necessary steps.


I have not finished my project yet. So I may hit new problems. But this is a big progress or myself after two weeks of trial and error.

Thank you for your attention.

1 decade ago by neogope

Hi Patrick,

thanks for your reply on the other thread and also for sharing your outcome here.

Unfortunately it still doesn't work for me, neither in plain Ejecta, nor if I directly include the code in the main.js. Everytime I call the iap.getProducts function it writes the right output (title, price, description) to the console, so the connection to the Appstore seems to work. After waiting a few seconds, I always get an error message like this

2013-08-20 18:49:01.275 Ejecta[806:907] -[__NSCFString pointerValue]: unrecognized selector sent to instance 0x1cd45c90

2013-08-20 18:49:01.277 Ejecta[806:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString pointerValue]: unrecognized selector sent to instance 0x1cd45c90'
*** First throw call stack:
(0x3347c2a3 0x3b2e597f 0x3347fe07 0x3347e531 0x333d5f68 0xfdf29 0xa1da5 0x1649c9 0x21b18b 0x21b3bd 0x1307b7 0x12f74d 0x334515df 0x33451291 0x3344ff01 0x333c2ebd 0x333c2d49 0x36f772eb 0x352d8301 0xafe99 0x3b71cb20)
libc++abi.dylib: terminate called throwing an exception

First I thought it could happen, because the purchase call is directly after the getProducts call, so I shove it into an extra function, but still the same. I also tried the latest Dev version of Ejecta with the XCode 5 Dev preview, outcome was the same.

As I am hanging on this issue like a week by now, I don't know what else to do :(

If anybody can offer some help, or has a working plugin to integrate into Impact that would be really really great (as it is the only thing that hinders me from finishing my game).

1 decade ago by Patrick

I am using Xcode 4.6.3 (4H1503). Do you want me to send you a ZIP of the working example? If yes, send me a mail.

patrick@fivedeer.com

1 decade ago by Patrick

By the way, neogope, I finally decided to not offering the IAP, mainly due to the fact that the codes do not seem to handle timeout. It just wait forever if I turn the iPad into Flight mode or disable the WiFi. I do not want to have stale threads around.

Therefore, I am making my new game, Rain of Vowels HD, a $2.99 game.

But I am happy to send you my working example. Just want you to aware of this issue I have.

1 decade ago by neogope

Nevermind, I got it (finally) :)

I will try to clean up my code a little bit and pack it into a plugin that can simply be used in Impact/Ejecta.

Not sure, where your problem with the (non-) timeout exactly happens, I couldn't find a problem with my implementation.
Page 1 of 1
« first « previous next › last »