Hey,
I implemented IAPs to my game (iOS), mostly successfully. However, I tested the following:
1: Start purchasing process in game
2: Suspend the game before the native iOS Apple ID password prompt
3: Now in iPhone menus, having the prompt still on top, enter the password and complete the purchase
4: Kill the game from the background
5: Open the game again
This resulted to a situation where the game is trying to finish the purchase by asking the password again. However, it also results in a null reference exception in OnPurchaseFailed.
I tested with no content in OnPurchaseFailed, and it still happens.
So now I’m locked out of my game, since the crash happens always in the very beginning, when I initialize the purchasing and the transaction tries to finish.
The code is very simple, but here’s the empty OnPurchaseFailed anyhow:
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
}
I can’t get my head around what could be causing the null reference.
Any help appreciated!
This bug is particularly devastating since I cannot get into the game even with another Apple ID, rebooting the device or re-installing the application.
Is there a way to clear all purchases from an Apple ID? I guess that’s something that Apple would need to do…
The bug seems to exist in Unity and how they handle this specific situation.
Was there any resolution to this? I am stuck with this exact bug as well.
Are you instantiating multiple ConfigurationBuilder instances? There is currently a bug in our StandardPurchasingModule that could lead to this behaviour if multiple ConfigurationBuilders are created - it should be a singleton, which our next update enforces.
No, there are not multiple ConfigurationBuilder instances.
Here’s the repro for how I got into the situation:
- Use an IOS device (haven’t tested this on my Android devices).
- Implement product purchases using Unity IAP.
- Run game on IOS device.
- Press your in-game button to initiate purchase.
- Mid product purchase, kill the game. Kill it somewhere after iTunes sign-in, before the final purchase success and/or thanks dialog. This happened easily for me because my Internet connection was extremely slow.
- Now re-start the game.
- Game crashes every time – because the Apple to Unity IAP process attempts to complete the aborted purchase from 4 & 5 before the listener functions are loaded in memory. That’s my guess because the xCode crash dump shows the listener functions hit a null reference exception.
- From now on, attempting to start the game will crash.
Pretty terrible, but wouldn’t be that uncommon in the wild with millions playing and slow internet connections (so common on phones). Luckily I did figure out a way to clear this situation for my locked out game.
Here’s how I cleared it:
- Put IOS device in Airplane mode so there is no Internet connection.
- Get into the game where a purchased product could happen (where IAP listener code would be resident in memory).
- Take the IOS device out of Airplane mode.
- Go back to game (still running in memory).
- Instantly the aborted purchase (from before, 3 days before in my case) will occur, providing you with the product.
- The game will now run normally and all subsequent purchases will operate properly.
As you can imagine this situation could happen quite frequently when millions of users are using Unity IAP in their IOS games.
I cannot reproduce this using these steps and the Unity IAP demo scene. It may be related to something else in your project setup.
Please submit a bug using a repro project and any associated XCode logs and post the bug number here.