Search code examples
iphoneobjective-ciosin-app-purchase

iOS -- How to save in-app purchase data?


I'm planning on implementing some in-app purchase items and I want to save purchase information/data such that iTunes will backup said information when my customers sync. The Apple provided documentation states that this is possible, but doesn't really tell you how.

Where/how do I save purchase history (let's say, a NSString for each item) such that iTunes will back it up on the next sync?

Lastly, how would you suggest that I test this before making all of this go live?

Thanks.

P.S. Right now I'm using NSUserDefaults to store this info.


Solution

  • NSUserDefaults is fine for storing that kind of thing, but you should also use StoreKit's “check for purchased items” capability—a lot of apps that use in-app purchases have a button somewhere that checks the “purchased” state of the available products and re-enables them in the app, in case a user uninstalls and then reinstalls the app or installs it on a different device.

    Testing in-app purchases can be done using the sandbox environment—iTunes Connect will let you set up a test iTunes Store account which has free access to all of your app's in-app purchases.