Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "MKStoreManager.h"
- #define kPartyPackPurchaseID @"partypack012"
- @interface ViewController ()
- - (void)hidePurchaseViewsForPurchaseID:(NSString *)purchaseID;
- - (void)unlockContentAssociatedWithPurchaseID:(NSString *)purchaseID;
- - (void)initiateTransactionForPurchaseID:(NSString *)purchaseID;
- - (void)restoreAlreadyPurchasedContent;
- @end
- @implementation ViewController
- - (void)hidePurchaseViewsForPurchaseID:(NSString *)purchaseID {
- if (purchaseID == kPartyPackPurchaseID) {
- //hide your button that leads the user to purchase the party pack
- }
- }
- - (void)unlockContentAssociatedWithPurchaseID:(NSString *)purchaseID {
- if (purchaseID == kPartyPackPurchaseID) {
- //purchased3Player.hidden = NO;
- //purchased4Player.hidden = NO;
- //commented because otherwise it would throw compiler errors for obvious reasons
- [self hidePurchaseViewsForPurchaseID:purchaseID];
- }
- }
- - (void)initiateTransactionForPurchaseID:(NSString *)purchaseID {
- [[MKStoreManager sharedManager] buyFeature:purchaseID
- onComplete:^(NSString *purchasedItemID) {
- [self unlockContentAssociatedWithPurchaseID:purchasedItemID];
- }
- onCancelled:^{
- //user canceled the transaction
- }];
- }
- - (void)restoreAlreadyPurchasedContent {
- NSString *MKStoreKitInfoPlistPath = [[NSBundle mainBundle] pathForResource:@"MKStoreKitConfigs" ofType:@"plist"];
- NSDictionary *MKStoreKitDictionary = [NSDictionary dictionaryWithContentsOfFile:MKStoreKitInfoPlistPath];
- NSArray *listOfPurchaseIDs = [MKStoreKitDictionary objectForKey:@"Non-Consumables"];
- for (NSString *purchaseID in listOfPurchaseIDs) {
- if ([MKStoreManager isFeaturePurchased:purchaseID] == YES) {
- [self unlockContentAssociatedWithPurchaseID:purchaseID];
- }
- }
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self restoreAlreadyPurchasedContent];
- }
- - (void)userPressedButtonToPurchasePartyPack {
- if ([MKStoreManager isFeaturePurchased:kPartyPackPurchaseID] == NO) {
- [self initiateTransactionForPurchaseID:kPartyPackPurchaseID];
- }
- }
Add Comment
Please, Sign In to add comment