How should I handle timeout when checking receipt of an In-App Purchase?
I am using the in-built Unity IAP system for my Android game.
When the game starts I initialise everything, then I perform a check to see if the player has a receipt for one of the products (actually the only IAP product I have at the moment).
I call this function after initialisation. It broadcasts a message to uScript, which I am using to handle all my game logic.
Product product = m_StoreController.products.WithID(productId);
if (product.hasReceipt)
{
Debug.Log ("Product has receipt.");
uScriptCustomEvent.BroadcastCustomEvent("ProductOwnershipConfirmed", productId, gameObject);
}
else
{
Debug.Log ("Product does not have receipt.");
uScriptCustomEvent.BroadcastCustomEvent("ProductOwnershipDenied", productId, gameObject);
}
The problem I have is that the code hangs on this step the first time you launch the app. But if I quit the app and immediately relaunch it then it works. If I leave it for a little while it goes back to not working.
I don't know if perhaps it's failing to initialise quickly enough so it's unable to perform the check...? Is there a way I can get it to keep trying and time out if it keeps failing? What's the best way to handle this scenario?