trouble mixing ObjC and C++ for in app purchase

ooops!!! I made a mistake while copy pasting the code here!!

the .cpp file (.mm)

I forgot to include the @end and the implementations of the 3 states!!!
I fixed it now
Can you TRY AGAIN!!!

on my machine it compiles I do the transaction I add my password and it says that my password is not a sandbox.

So it returns “transaction Failed”…

I went to bed, sorry for the delay. So it’s compiling, but I get transaction failed even with the correct login. I did however already “purchase” the item using the tutorial so maybe it’s failing because I already own it? I’ll make a couple new test users and try again.

This is very exciting and we are a step forward since we are at least getting a response from the buy :slight_smile: :slight_smile: :slight_smile:


meh… I think it should say… “reclaimed” when you already bought it…

we must check for more steps…

…create a new object in itunes connect?

well… back to the drawing board I guess… let me know if you got any progress…

I ll have another play this evening.
The tact that paymentqeue is now triggering is very encouraging!
I ll create another product and see how that works

I noticed that we are not using “SFHFKeychainUtils” object in our paymentQueue, or anywhere else, maybe this sends an OK signal to itunesConnect before the transaction is completed?

also… maybe we need to “close” the store at the end?

or maybe we are doing that already with finishTransaction?

The keyutils thing is just a way of remembering that the purchase was made. It doesn’t affect the process. I ll be home in a couple hours And will poke around

…oh, I see, so It’s just for internal consumption, we can ignore that completely, there better ways to do what that monster does…

…we also neglected that part:
it checks for parental control before purchase

if (alertView==askToPurchase) {  
        if (buttonIndex==0) {  
            // user tapped YES, but we need to check if IAP is enabled or not.  
            if ([SKPaymentQueue canMakePayments]) {   
                SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.emirbytes.IAPNoob.01"]];    
                request.delegate = self;    
                [request start];    
            } else {  
                UIAlertView *tmp = [[UIAlertView alloc]   
                                    message:@"Parental Control is enabled, cannot make a purchase!"  
                                    otherButtonTitles:@"Ok", nil];   
                [tmp show];  
                [tmp release];  

also I remember reading somewhere that ios6 brakes in-app purchases, so maybe they is something additional now?, I am positive our “tutorial” is quite old…

Agreed, it is pretty old but it worked fine when I tested it.


So I’ve been playing with it for another hour with no avail! Arrgg

I tried adding new product, changing user accounts and all sorts but always get “Error payment cancelled” printed to the terminal.

Here is the project in it’s latest form:

I’m lost at this point :frowning:

I tried running the tutorial again and it still works as expected with the same product, but I can’t figure out what broke in the translation to OF. I’m happy to share the test username credentials with anyone willing to try it out.

Just PM me, I prefer not to post it publicly…

I do have a crazy idea for a possible workaround:

Given that we know that the tutorial project works, I wonder if it be possible say to temporarily exit the OF testApp, load the tutorial app (AppDelegate?), make payment then return back to appTest OF after payment successfully completed?

Here is the working tutorial project:


…again… I can’t test that bloody example (the tutorial) it doesn’t allow me to compile…

if you want to access the tutorial from your app…

you can:

  1. add viewController.h files in scr and the assets (recreate the project basically)

  2. #include header viewController.h in test app

  3. declare a pointer ViewController *viewController; in testApp class

in .mm

4 inside setup:

  testApp::viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];  
    ofxiPhoneGetUIWindow().window.rootViewController = testApp::viewController;  
    [ofxiPhoneGetUIWindow().window makeKeyAndVisible];  

this should activate the tutorial… but I haven’t tested it
I can’t,

if your account is empty like mine, send me the sandbox passwords to try figure this shit out…
you can change the password after…! right?
PS (i think another guy in the forum implemented inApp purchases a while ago )

Thanks for helping out. Here are my test user details:

password: Qwertyu8

Yeah apparently Marc Sallant got it running in his awesome Sr. Mistu game:—the-great-olive-pursuit/6653/0

I sent him an email and bumped the thread, maybe he can shed some light :slight_smile:

In the meantime I’m going to try to launch the tutorial from testApp as you described.


ok I got them, edit them out.


OK MAN… I think I figure it out. I got a positive result.

I am going to clean it out and post an addon tomorrow…



You’ve earned a big case of beer or a bottle of good wine, your choice, my command


I’ve finished the addon

do you ship beers abroad Alex? we could use some booze here in greece to overcome our problems…

to use the Addon you must first create an in-app object at Apple’s itunesConnect website, and also activate the sandbox account to test it.

     remember to add "StoreKit.framework" && "Security.framework"  

The addon has two constructors

you can either just put the name of your product
and the addon will automatically put an unlock password and an appname
(different for every object you have)


you can call

dubKit = new ofxInAppProduct(“alkex.dubstep.toolbox”,“1234”,“myAppName”);

to specify your own password and appname.

Use a new ofxInAppProduct for each in-App object


    dubKit = new ofxInAppProduct("alkex.dubstep.toolbox");  

the Addon creates unique password for every object and saves it in the registry to a very hard to find place

//OR if you want to specify your own passwords and appname call the other constructor:

    dubKit = new ofxInAppProduct("alkex.dubstep.toolbox","1234","samploid");  

and/// when ever you want to buy smthng:


oh… if for any reason you want to un-purchase something on a device: call


/// the addon also provides a bool to check if the product isPurchased

so can you do:

//do stuff  
//do otherstuff  

it is designed in such a way so that it only checks in the registry once so if you have a ton of products it wont affect your app. you can call everything inside a loop

I haven’t tested the Addon with more than one products yet, – I don’t think there will be any problems but DO LET ME KNOW with a pm or email if there is any bug.




11NOV 12:00
***Fixed bug that forgot to check if Parental Control was enabled

Hi there!
Thanks so much for setting this up!!!

I must have messed something up because it was working fine (in IOS6, not IOS5) before the parental bugfix but now it won’t. I’ll play with it some more.

I’ll keep you posted! Awesome job

To remove parental control

do this:

![]( shot 2012-11-12 at 05.54.42.png)

I think there was a goblin in the works, I cleaned the project and reset the simulator - works like a charm!
I emailed your gmail :slight_smile:

Thanks again!

Minor Update:

||----Major Bug Fixed-------||

I just spotted a security bridge

If you only had one inApp purchase the previous code would work

but with multiple things on the store, the previous code had a major security problem

**NOW IT’S FIXED so please use this version


*a loading bar while you are trying to reach the server

*a boolean isTransactionFinished() while transaction is happening is false while canceled or finished or purchased is true;

*a reset() Bool that might be needed to be called if you want to try buy again if the user clicks Cancel (before when you clicked cancel you had to restart the app to be allowed to try buy the object you canceled again


*changed the Random username selection process that Addon provided behind the scenes now the Random username (if not specified using the second constructor) is the NAME OF YOUR APP, for example in an empty example it will be: empty example

I feel confident to say that you can use the addon without specifying your own names,

specify your own names if:

you have a two versions of the same app, like HD/Normal with different bundle names and you want users that bought stuff in the other app not having to rebuy them if they already bought them (on the same device)

not sure if you can specify the same product in two apps from itunes connect like you can do with the GameCenter scores.


there is a bug, when you delete the object and then recreate it, if you do that you can’t re-try buy, there is a bug deep inside the addon that I am unable to fix…in simple english: if you click buy then cancel and then delete the object and create a new object and try to buy the same product again it crashes.


Declare alloc and initialize the addon (using the **new **operator) ONCE at the setup and pass it around with pointers


make them Global objects.

release the object if you like on Exit()

…hope this makes sense.


Hi Kyri!

Sorry for the delay, I’ve been out of town for the weekend and have been away from the project for a few days, I can’t wait to try the new version, Thanks for all the updates!!!