Working on adding in-app purchasing to my app (working on iOS only at the moment, will work on Google Play after this all works) and running into a bit of an issue that is not breaking anything, but it just a little ugly.
For the in-app purchasing, I have several non-consumable items that can be purchased. I have a “modal” screen that appears that lists all of the products with purchase/select buttons. (Each item can only be used one at a time, so the screen also doubles as the one to select which one to use.)
The way it works is that after a user successfully purchases an item, we display a native.showAlert that says the purchase was successful with an OK button, like such:
native.showAlert( "APP NAME", "Your purchase is complete.", { "OK" }, reloadModalScreen )
When the user clicks OK, we reload the modal screen which updates the state of the item to allow the user to select it. Works great.
We have the same behavior with the “Restore purchases” button.
native.showAlert( "APP NAME", "Your previous purchases are restored.", { "OK" }, reloadModalScreen )
The issue is that since multiple restores can occur, this means that multiple alerts appear and the modal screen reloads for each one, which works fine, but is just a little ugly.
Can anyone suggest a way to get around this and just reload once after all the restores occur, without knowing how many there are going to be?
Sadly, since the content of the modal screen is dynamic (built from an XML file), and my LUA programming skills are hardly advanced, I haven’t figured out how to just update the existing screen instead of reloading it.
While kludgy, I was thinking of just setting a variable when we reload the screen, and doing a check to see before we reload (or show the alert) to see if it was just reloaded in the last minute, and if so, don’t reload or display the alert. It seems possibly problematic though becuase if there is a delay between the restore callbacks, then when the first reload happens, the later restores might not be captured in the new screen. Probably unlikely, but I was concerned.
Any recommendations would be greatly appreciated.