Products not seen as purchased in TestFlight builds
jzting opened this issue · 6 comments
I'm seeing the following behavior only in TestFlight builds. This is with configuration .default.
- Purchase a product
- Force quit the app and restart
In the didChangeStatesFor: callback, the product purchased in step 1 doesn't seem to come back as .purchased. Note that it does get returned when calling restorePurchases().
What's strange is that in dev builds, the product comes back as .purchased. Is this expected behavior because of the difference between sandbox and production iTunes accounts?
When you are checking the didChangeStatesFor callback? When the app is relaunched?
At first glance, this sounds like a sandbox/production discrepancy but not 100% sure based on your description.
Yes, I'm calling fetchDataIfNecessary() on the product interface controller when the app is launched and then checking didChangeStatesFor callback.
You won't get the didChangeStates callback every time. If the app was purchased previously, it will already be purchased when you next launch and you won't get a callback because nothing has changed.
After calling setup()
in your AppDelegate, you should check the current state of a product if you aren't storing it somewhere already and use that. Then, be ready to respond in the didChangeStates delegate if the state of any product changes after the app is launched.
Ah, gotcha, so I should manually check if a product is purchased by calling merchant.product(withIdentifier: "iap.productidentifier"). Thanks!
Glad I could help.
One pattern that might be useful is to declare the Product
objects as globals or namespaced globals like let product = Product(identifier: "iap.productidentifier", kind: .nonConsumable)
or whatever. Then, you can pass that instance around into the register(...)
method, into Merchant.state(for: product)
etcetera etcetera.
As a general rule, the ProductInterfaceController
object should only be used when tied to the storefront/purchase interface. Outside of those contexts, use the Merchant
directly.