In the past months, several requests about In-App Purchase (IAP) with Kwik came up and, according our police to provide your requests first, I would like to announce that IAP will be one of the top features of the upcoming 1.7 version. I have to say that I am curious why this is one of the top requisitions. IAP is complex to setup (more below) and most of the current apps made with Kwik at this moment don’t seem to require this new feature.
Saying that, I would like to anticipate how to use IAP with Kwik 1.7.
First thing to understand is that IAP can be implemented in two different ways when users buy a product from your app:
- an internal asset (a page, or an addition of points, for example), previously locked, becomes available after the purchase;
- An external asset (more levels or a new magazine issue, for example) is downloaded and integrated into the current application;
Kwik will work with the first scenario only. It means the pages that will be unlocked need to reside into your app (more details below).
IAP is complex mostly because it does not allow you to test your application in the Simulator and, part of the code needs to reside in Apple’s servers. So, how to setup IAP? As several “how-tos” mention (see some below), you are going to spend more time working in Apple’s side (configuring profiles, etc) than with Kwik.
Start reading this great walk-through from Troy Brant’s (the code part is not important as Kwik will handle it for you):
- Basically you will need to create a Unique App ID
- Create a new provisioning profile
- Add you application to iTunes
- Upload your app binary (even if it is not finished) – you need a binary to create a product
- Add your product(s)
IAP in Kwik
As mentioned before, Kwik only works with internal asset purchases. Considering it uses the concept of pages, imagine that some pages will be unlocked only when the user purchase them. You may have a free storybook that allows the reader to read until the middle of the story. To finish it, he/she needs to buy the rest of the pages.
In this example, I created a three page project. Users can read page 1 and 2. Going to page 3 the user will receive a message informing that page is locked. It will re-direct the user to the first page, which contains a button for purchase.
Step 1 – Add products to your project
The project area now has a few new features. The IAP one is represented by a credit card.
Click it to enter the products you plan to sell (you see the list of all previously entered products:
Click the + button to enter more products:
In this window, inform exactly the same product id created in iTunes Connect, otherwise your app will not work. For the name, DO NOT enter names with spaces. As convention, use the last word of your product id as name. In my example above, as my product id is com.asouza.candice.epilogue, I named the name field as epilogue.
Step 2 – Add a button enabling the purchase process
Select a layer and click Add Button. You will notice two new button actions:
The first button allows you to buy a product, which needs to be selected via the following window:
I added an option to auto hide the button after purchase. Just enable the check box and the code will be added for you.
The other button allows you to Restore previous purchases (in the case the user bought them and uninstalled your app – it is not fair he/she needs to pay again, right?).
Step 3 – Select the page you need to protect
When in the page you need to protect, go to the Page section and click the new button (same credit card icon):
Now select the product you want to enable for purchase and the page you want to re-direct users who haven’t purchase yet:
All you need now is to export your project and Build it for your device (remember IAP projects do not work on the Simulator), using the same certificate you used in iTunes Connect. Using the test account you created, click your BUY button and you will get access to the previously locked page!
Comments? I would love to hear them!
PS: With version 1.7.2 you are now able to have more than 1 purchase button per page.
Only 1 purchase button per page is allowed (you cannot create, for example, two buttons pointing two different products in the same page);
PS2: If you need to do what is the magic behind the code, Kwik simply creates a local file into users Documents folder. When the locked page is reached, it checks if the local file exists. If not, it will alert and send the users to the predefined pageError.