Search code examples
iosin-app-purchasemkstorekit

Implementing two consumables with MKStoreKit


How should I implement two consumables with MKStoreKit? If I have two consumables, for example "handful of coins" (10 coins) and "bag with coins" (100 coins). I have two questions:

  1. How should product IDs look like?

  2. How to get overall amount of purchased coins, including ones from handful(s) and from bag(s)?

    Amount = 10*handfuls_purchased + 100*bags_purchased;
    

I've read tutorial on official MKStoreKit blog but I still just can't figure this out.

P.s. I'm using MKStoreKit 3.1 and can't update to more recent version because of ARC (my project doesn't support it)


Solution

  • Your plist's consumables key should look like this.

    <key>Consumables</key>
        <dict>
            <key>com.yourcompany.yourapp.handfulofcoins</key>
            <dict>
                <key>Count</key>
                <integer>10</integer>
                <key>Name</key>
                <string>CoinsInMyApp</string>
            </dict>
    <key>com.yourcompany.yourapp.bagofcoins</key>
            <dict>
                <key>Count</key>
                <integer>100</integer>
                <key>Name</key>
                <string>CoinsInMyApp</string>
            </dict>
        </dict>
    

    I match the String "CoinsInMyApp" to calculate the number of purchased coins no matter which consumable they come from. In the above example if the user buys 1 bagofcoins and 2 handfulofcoins, MKStoreManager stores 120 for the key CoinsInMyApp.

    methods,

    - (BOOL) canConsumeProduct:(NSString*) productIdentifier
    - (BOOL) canConsumeProduct:(NSString*) productIdentifier quantity:(int) quantity
    

    will tell you if you have enough products.

    When the player uses coins, you should let MKStoreKit know this by calling

    - (BOOL) consumeProduct:(NSString*) productIdentifier quantity:(int) quantity
    

    You can get the number of coins by calling

    [[MKStoreManager numberForKey:@"CoinsInMyApp"] intValue];
    

    PS: You can use MKStoreKit latest version in a non-ARC project by compiling it with the -fobjc-arc flag.

    I wrote about this here http://blog.mugunthkumar.com/articles/migrating-your-code-to-objective-c-arc/