Sunday, December 3, 2017

networking - Unity IAP through Google Play is forgotten after a day without internet connection



I am trying to make a NonConsumable IAP purchase persist without internet connection.


I have implemented the IAP system from Unity 5.6 through Google Play for a NonConsumable item and it is working. From a previous question I learned how to avoid using Unity's PlayerPrefs to remember purchases in favor of checking the receipt from the Unity storeController that initializes with Unity's API code below.


   public void OnInitialized (IStoreController controller, IExtensionProvider extensions)
{
this.controller = controller;
this.extensions = extensions;
}

What I have observed is that the OnInitialized will run without internet connection as long as it has recently been initialized. This seems to be cached somewhere within Android because clearing the cache on my app will not force the purchase to be forgotten. The problem is after about half a day without internet connection the controller cannot initialize. Therefore I cannot check the item receipt in the controller with the code below.


Product product = storeController.products.WithID(productId);

if (product != null && product.hasReceipt)
{
// Owned Non Consumables and Subscriptions should always have receipts.
// So here the Non Consumable product has already been bought.
itemBought = true;
}

What strategy or method should I use to persist a NonConsumable purchase during times without internet connection as it is recommended to not use Playerprefs on numerous guides.




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...