Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Products not seen as purchased in TestFlight builds #41

Closed
jzting opened this issue Oct 19, 2019 · 6 comments
Closed

Products not seen as purchased in TestFlight builds #41

jzting opened this issue Oct 19, 2019 · 6 comments

Comments

@jzting
Copy link

jzting commented Oct 19, 2019

I'm seeing the following behavior only in TestFlight builds. This is with configuration .default.

  1. Purchase a product
  2. 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?

@benjaminmayo
Copy link
Owner

benjaminmayo commented Oct 24, 2019

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.

@jzting
Copy link
Author

jzting commented Oct 24, 2019

Yes, I'm calling fetchDataIfNecessary() on the product interface controller when the app is launched and then checking didChangeStatesFor callback.

@benjaminmayo
Copy link
Owner

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.

@benjaminmayo
Copy link
Owner

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.

@jzting
Copy link
Author

jzting commented Oct 24, 2019

Ah, gotcha, so I should manually check if a product is purchased by calling merchant.product(withIdentifier: "iap.productidentifier"). Thanks!

@jzting jzting closed this as completed Oct 24, 2019
@benjaminmayo
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants