*** NOTE: The in-app purchase items that are included in the sample code will only work if you are accessing the US app store. If you are outside of the US, you will have to create your own application and in-app purchase items, and overwrite the ID’s that we specify in the code. Thanks to reader Ben Rad for pointing out that it also will not work with jailbroken iOS devices! ***
Hey everyone – we’re in the midst of a project where we’ve just had to implement In-App purchases, so we figured we would get this quick little tidbit of info out to you all. What we’ve put together is a quick sample app based off of Ray Wenderlich’s tutorial. Ray’s tutorial was based off of UIViews, and we here at iPhone Game Tutorials love Cocos2d (download here!) so we ported this over. Hopefully this helps someone make some big bucks!
Source after the break!
You can download our example here. It should display a list of Ray’s in-app items and their price – you can click on the price to purchase the item. One important thing to note is you have to test this on a device – in app purchases do NOT work in the simulator! There’s still a couple other things you have to do before testing. From Ray’s site:
While you’re running your app in XCode, you’re not running against the real In-App Purchase servers – you’re running against the sandbox servers.
This means you can buy things without fear of getting charged, etc. But you need to set up a test account, and also make sure you’re logged out of the store on your device so you can see the whole process.
To make accounts, log onto iTunes Connect and click “Manage Users”. Click “Test User”, and follow the buttons to create a test user that you can make dummy in-app purchases with on the sandbox servers.
Then go to your iPhone and make sure you’re logged out of your current account. To do this, go to the Settings app and tap “Store”, and then click “Sign Out.”
Also, to test with your own app, you need to first create the app with a unique bundle identifier (like “com.yourcompanyname.appname”), then set the bundle identifier to match that in the Info.plist file. Then you’ll need to configure your new app for in-app purchases in the iOS Provisioning Portal under the App ID’s section, and finally create a new provisioning profile associated with the new app. Side note – you can do all this with an existing app if you like, as long as you configure it for in-app purchases and re-download/install the provisioning profile associated with that app.
Once you’ve got that all setup, you’ll want to change lines 28-32 in InAppRageIAPHelper.m to match whatever product identifier you gave your in-app products.
That’s really all there is to it – good luck and post any questions in the comments!