How to download in-app after onsuccess transaction

Hi,
I did few month ago a cocos2d-x ios app with in-app coded in pure objC. Now I try to use the sdkbox for a new app that will be on ios and android.
In objC I did:

[[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];

How can I acheive that in the OnSuccess callback? Do I have to call objC? Where is the transaction?

I have no problem with something like buying coins or removing ads in app because the information is in the Product received in parameter.

Thank you!

1 Like

Hello @cocos99d

If you are using SDKBOX IAP plugin,
then you must have overrided the onSuccess() on the class where you have used your IAP.
once the IAP purchase is successful, then it will come inside onSuccess() function and you can access the product like this -

if(p.name == “REMOVE_ADS”)
// do something

Let me know, if it answers your question after trying.

Best,
Pabitra

This functionality is for hosted in-app content correct? We didn’t implement it since it’s not available on android platform yet.

1 Like

thank you @nite,

yes, it is for hosted content and you just gave me the answer I was afraid to receive. So I guess I have 2 choices: first I will dig into the sdk to see if I can add this functionally for my ios app, or I just forget about sdkbox :grin:

or, third solution, I call a objC function in onSuccess() to ask Apple to send me back the last transaction??? What do you think about that?

That might work, not sure though, I’m thinking about how are you going to handle in-app content download in android version? If you’re going to host the content on your own webserver for the android version, maybe you can reuse the same logic?

That is a good point! I was more concerned about the ios version that I’m working on now and did put aside android. Having Apple host my in-app content was an easy solution. I will not postpone it any more and will switch to my server.
Thanks for your help @nite ! :wink:

if I call objC function in onSuccess() to ask Apple to send me back the last transaction, wgat is the parameter i should use inside transaction.payment.downloads

 -(void) download:(StoreTransaction *)transaction
  {
   NSAssert(transaction.payment.transactionState == SKPaymentTransactionStatePurchased ||
            transaction.payment.transactionState == SKPaymentTransactionStateRestored, @"The payment transaction must be completed");

if ([transaction.payment.downloads count])
{
    [[SKPaymentQueue defaultQueue] startDownloads:transaction.payment.downloads];
}
}