Issues with Restoring IAPs

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MrCrussell
Posts: 23
Joined: Wed Nov 05, 2014 11:30 am

Issues with Restoring IAPs

Post by MrCrussell » Wed May 17, 2017 5:05 pm

Hi all,

I've been messing about trying to get IAPs to work for what felt like forever and now I'm at the final stage, which is trying to get previous purchases to restore properly.

According to the docs, tutorials etc, if I set up a button which triggers the following:

Code: Select all

   mobileStoreEnablePurchaseUpdates
   mobileStoreRestorePurchases
If I read the docs correctly, this should return a list of ALL prior purchases linked to a user's account and cycle through them one at a time. My problem is that doesn't seem to be happening.
Having tested on a live device, if I tap the button I see the first purchase come through but thereafter nothing, even when I know there are more purchases to deal with.

Do I need to loop through the purchased list to get them all processed, and if so, how do I do it?

TIA

MrC

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 818
Joined: Fri Feb 06, 2015 4:03 pm

Re: Issues with Restoring IAPs

Post by LiveCode_Panos » Wed May 17, 2017 7:29 pm

Hi MrC,

The command "mobileStoreRestorePurchases" will trigger a callback to the "purchaseStateUpdate" message. The "purchaseStateUpdate" message will be called as many times as the number of **non-consumable** items you have already purchased, each time with a different productID and purchaseID, but always with the same state, "restored".

If you see the first purchase come through but thereafter nothing, I guess that:

- Either you have only one **non-consumable** item to restore (consumable ones are not restored)
- Or in the "purchaseStateUpdate" message, where you handle the pState=restored, you have a call to "mobileStoreDisablePurchaseUpdates". If this is the case, after the first purchase is successfully restored, you no longer get updates from the AppStore, because "mobileStoreDisablePurchaseUpdates" terminates the communication with the AppStore. So you have to call this command (i.e. "mobileStoreDisablePurchaseUpdates") once *all* the purchases are restored.

Hope this helps,
Panos
--

PS: I guess you are on iOS, is that correct? If yes, can someone move this thread to "iOS Deployment"?

MrCrussell
Posts: 23
Joined: Wed Nov 05, 2014 11:30 am

Re: Issues with Restoring IAPs

Post by MrCrussell » Thu May 18, 2017 10:07 am

Thank Panos, I'll try it out.

This should be in iOS Deployment, apologies.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Issues with Restoring IAPs

Post by Klaus » Thu May 18, 2017 10:49 am

Your wish is my command! :D

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 818
Joined: Fri Feb 06, 2015 4:03 pm

Re: Issues with Restoring IAPs

Post by LiveCode_Panos » Thu May 18, 2017 10:52 am

Thank you Klaus :)

MrCrussell
Posts: 23
Joined: Wed Nov 05, 2014 11:30 am

Re: Issues with Restoring IAPs

Post by MrCrussell » Wed May 24, 2017 7:35 pm

So, I've picked through the code and I even removed any mention of mobileStoreDisablePurchaseUpdates and I'm still seen the same behaviour - every time I call mobileStoreRestorePurchases I get one item only. The items I'm trying to restore are all non-consumable and every time I test I use a new user (to make sure I don't get contaminated results). I've also checked to make sure there are no rogue disablePurchases anywhere .

I'm pretty much about ready to give up and rewrite the project in Swift. Can anyone shed any light on what's going on?

The code for the button triggering the restore is:

Code: Select all

on mouseUp
   answer( "Execute Restoring Purchases" )
   mobileStoreEnablePurchaseUpdates
   mobileStoreRestorePurchases
end mouseUp


and the purchaseState code is stored in the stack script :

Code: Select all

on purchaseStateUpdate pPurchaseID, pProductID, pState
   switch pState
      case "paymentReceived"
         offerPurchasedProduct pProductID
         mobileStoreConfirmPurchase pProductID
         mobileStoreDisablePurchaseUpdates
         // other code removed
         break
      case "error"
         answer "Error occured during purchase handling:" & return & return & mobileStorePurchaseError(pPurchaseID)
         mobileStoreDisablePurchaseUpdates
         break
      case "invalidSKU"
         answer "The SKU was invalid"
         mobileStoreDisablePurchaseUpdates
         break
      case "alreadyEntitled"
         answer "You already own this module"
         mobileStoreDisablePurchaseUpdates
         break
      case "restored"
         offerPurchasedProduct pProductID
         mobileStoreConfirmPurchase pProductID
         // answer ("restored: " & pProductID) 
         // mobileStoreDisablePurchaseUpdates
         break
      case "cancelled"
         answer "Purchase cancelled for " && pProductID
         mobileStoreDisablePurchaseUpdates
         break
   end switch
end purchaseStateUpdate

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 818
Joined: Fri Feb 06, 2015 4:03 pm

Re: Issues with Restoring IAPs

Post by LiveCode_Panos » Mon May 29, 2017 12:07 pm

Hi MrCrussell,

Could it be the case that there is an error in your `offerPurchasedProduct` handler, which causes the execution to stop just after the first IAP is restored?

What happens if you comment out the call to `offerPurchasedProduct`? Do you now get as many callbacks of `purchaseStateUpdate` as the number of IAPs you expect to be restored?

Best,
Panos
--

Post Reply

Return to “iOS Deployment”