- Home /
IAP generates exception when calling m_StoreController.InitiatePurchase(product)
Hello,
I got an exception when calling m_StoreController.InitiatePurchase(product).
Following the Unity IAP demo, here is a fragment of my implementation of IAP:
public void buyProduct(IapType iapToBuy) {
Debug.Log("Entering buyProduct with iapToBuy: "+iapToBuy);
string productID=getIAPstringID(iapToBuy);
if (isInitialized()) {
Debug.Log("searching WithID:"+productID);
Product product = m_StoreController.products.WithID(productID);
Debug.Log("Product is available for purchase:"+product.availableToPurchase);
if ((product!=null) && product.availableToPurchase) {
Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
m_StoreController.InitiatePurchase(product);
}
...
} Here is overridden OnApplicationPause() :
void OnApplicationPause(bool status) {
print("App paused called with status: "+status); //debug only
}
And here is my log with the unwanted exception that appears once the Unity tries to suspend my app and just before Android purchasing dialog appears:
I/Unity (23779): Entering buyProduct with iapToBuy: iapLeverDown
I/Unity (23779): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
I/Unity (23779): searching WithID:carshift_lever_down
I/Unity (23779): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
I/Unity (23779): Product is available for purchase:True
I/Unity (23779): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
I/Unity (23779): Purchasing product asychronously: 'carshift_lever_down'
I/Unity (23779): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
I/Unity (23779): purchase({0}): carshift_lever_down
I/Unity (23779): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
I/Unity (23779): handlePurchases state:psPurchasingInProgress
I/Unity (23779): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
I/Unity (23779): handlePurchases state:psPurchasingInProgress
I/Unity (23779): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
I/Unity (23779): AndroidJavaException: java.lang.IllegalArgumentException: Receiver not registered: com.unity.purchasing.googleplay.GooglePlayPurchasing$3@2edbae3a
I/Unity (23779): java.lang.IllegalArgumentException: Receiver not registered: com.unity.purchasing.googleplay.GooglePlayPurchasing$3@2edbae3a
I/Unity (23779): at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:863)
I/Unity (23779): at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:2087)
I/Unity (23779): at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:529)
I/Unity (23779): at com.unity.purchasing.googleplay.GooglePlayPurchasing.OnApplicationPause(GooglePlayPurchasing.java:102)
I/Unity (23779): at com.unity3d.player.UnityPlayer.nativePause(Native Method)
I/Unity (23779): at com.unity3d.player.UnityPlayer.i(Unknown Source)
I/Unity (23779): at com.unity3d.player.UnityPlayer$18.run(Unknown Source)
I/Unity (23779): at com.unity3d.player.UnityPlayer.executeGLThreadJobs(Unknown Source)
I/Unity (23779): at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
I/Unity (23779): at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in :0
I/Unity (23779): at UnityEngine.AndroidJNISafe.CallVo
I/Unity (23779): App paused called with status: True
I/Unity (23779):
I/Unity (23779): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
I/Unity (23779):
All 4 basic IStoreListener listeners:
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
public void OnInitializeFailed(InitializationFailureReason error)
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
are implemented according to the IAP demo.
Purchaser is attached to only one object, init is called once only and the object is not destroyed between scenes. Exception appears only during the first call the method after app init. Purchase can be cancelled as well as completed and all subsequent events are delivered to the corresponding listeners.
One can say that the exception can be only ignored but the question is whether it does not signalize something more serious that would appear only in production.
Presumably, Unity tries to unregister receiver just before calling google's purchasing function but the receiver (which one?) is not registered..
Any thoughts, please?
Thank you,
Paul
Update: it has nothing to do with InitiatePurchase() function but rather with pausing the App. The same occurs when (after successful initialisation of the Purchaser) I click device HW left button (aka task manager) and the device offers to close app(s)... And again, only after the first call.