MKStoreKit, as you probably know is a framework for implementing In App Purchases in your app. It supports virtually every feature you could tell and every business model you could (or even Lodsys) ever think of. It supports, Auto-renewable subscriptions, Consumables, non-renewable subscriptions, and good old non-consumables and a whole lot others.

The biggest gripe among the developer community is that there is no easy to use, step by step guide on how to use it. There are reasons why I couldn’t publish one.

Why no demo?

First and foremost, a working demonstration app implementing MKStoreKit requires an app to be setup on AppStore and this app cannot obviously be published. Conversely, I cannot open source an app that makes money for me through In App Purchases.

If you have an App on iTunes Connect without publishing it, Apple will send you a polite email after 2 or 3 months asking you to publish. Failing which, they remove it for you and will no longer allow you to create an App by the same name. Deleting the app obviously removes associated In App Purchases and the demonstration code will no longer work. It simply doesn’t make sense to play cat and mouse with Apple and create dummy apps for a demonstration software.

Design of MKStoreKit

However, MKStoreKit has been designed keeping this in mind. The whole integration shouldn’t take more than an hour or so. Implementing the MKStoreKit into your app is as simple as 10 or 15 lines of code.

Step 1: Initialization The first step is the initialize it in the AppDelegate using the code,

[MKStoreManager sharedManager];

Step 2: The Plist magic The second step is to set up your configurations in the plist file, which I think is quite obvious. There are three keys in the plist, one containing an array of non-consumables, one containing an array of consumables and another an array of auto-renewable subscriptions.

Step 3: Configuring for Non consumables Non-consumables need no extra configuration. Just enter the list of product ids in the plist file.

Step 4: Configuring for consumables For Consumables, you need to tell MKStoreKit, which product it belongs to and the quantity it adds.
For example, com.mycompany.myapp.eggbasket1 = 10 eggs, and com.mycompany.myapp.eggbasket2 = 100 eggs, you need to tell MKStoreKit that both these are the same product “Egg” and they add 10 and 100 eggs respectively.

This is precisely what the keys Count and Name stands for.

Step 5: (Auto-renewable subscriptions) For auto-renewable subscriptions, you need to tell the subscription length. MKStoreKit automatically keeps track of subscription expiry and notifies you through NSNotificationCenter if they expire. Since, Apple doesn’t keep track of subscription length, it’s your responsibility (which MKStoreKit takes care of) as a developer to remember those subscription length somewhere in your app.

Step 6: (Shared Secret) If you use auto-renewable subscriptions, you need to enter set your shared secret. You should do this in MKStoreKitConfigs.h. If you don’t do this step, MKStoreKit cannot notify you of subscription expiry. Shared Secret is used for subscription verification and it’s compulsory to set this if you use auto-renewable subscriptions.

Step 7: The real purchase
The real purchase code is a one liner.

 [[MKStoreManager sharedManager] buyFeature:<strong>@"com.mycompany.myapp.feature1"</strong> 
                                    onComplete:^(NSString* purchasedFeature)
     {
         NSLog(@"Purchased: %@", purchasedFeature);
		// provide your product to the user here.
		// if it's a subscription, allow user to use now.
		// remembering this purchase is taken care of by MKStoreKit.
     }
                                   onCancelled:^
     {
         // User cancels the transaction, you can log this using any analytics software like Flurry.
     }];

Everything happens behind the scenes, automatically. For every kind of product, whether it’s a consumable or non-consumable, this code is same.

Step 8: Expiry notifications for auto-renewable subscriptions Subscribing to subscriptions revoked notifications (only for auto-renewable subscriptions).

	[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector (subscriptionExpired:) 
name: kSubscriptionsInvalidNotification 
object:nil];

It’s the configuration part that’s hard. So, as I promised that was under 10 lines right? One line in your AppDelegate, 4 or 5 lines in your Store ViewController and 2 lines to listen for subscription expiry notification. That wasn’t hard, was it?

Going forward

Lion

MKStoreKit will soon be released with full support for Lion
Currently, I think it should automatically work, though I haven’t tested it. If you are using it, do let me know.

iCloud

Adding iCloud integration. With iCloud, your purchases will be remembered on iCloud rather than Keychain, which means, you don’t need to restore transactions on every device. iCloud will do it for you automatically.

The code for this is ready, but the NDA prevents me to push it to Github. Wait till Sep 5th (hopefully)

If you have any other feature requests, or want me to look at your changes, do send me a pull request for the code on Github
http://github.com/mugunthkumar/MKStoreKit

Hope MKStoreKit helps you and your business. Do consider a paypal donation to mugunth.kumar@gmail.com.

Thanks,

Mugunth

Follow me on Twitter