Guest User

Untitled

a guest
Apr 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "MKStoreManager.h"
  2.  
  3. #define kPartyPackPurchaseID @"partypack012"
  4.  
  5. @interface ViewController ()
  6.  
  7. - (void)hidePurchaseViewsForPurchaseID:(NSString *)purchaseID;
  8. - (void)unlockContentAssociatedWithPurchaseID:(NSString *)purchaseID;
  9. - (void)initiateTransactionForPurchaseID:(NSString *)purchaseID;
  10. - (void)restoreAlreadyPurchasedContent;
  11.  
  12.  
  13. @end
  14.  
  15. @implementation ViewController
  16.  
  17. - (void)hidePurchaseViewsForPurchaseID:(NSString *)purchaseID {
  18.     if (purchaseID == kPartyPackPurchaseID) {
  19.         //hide your button that leads the user to purchase the party pack
  20.     }
  21. }
  22.  
  23. - (void)unlockContentAssociatedWithPurchaseID:(NSString *)purchaseID {
  24.     if (purchaseID == kPartyPackPurchaseID) {
  25.         //purchased3Player.hidden = NO;
  26.         //purchased4Player.hidden = NO;
  27.         //commented because otherwise it would throw compiler errors for obvious reasons
  28.         [self hidePurchaseViewsForPurchaseID:purchaseID];
  29.     }
  30. }
  31.  
  32. - (void)initiateTransactionForPurchaseID:(NSString *)purchaseID {
  33.     [[MKStoreManager sharedManager] buyFeature:purchaseID
  34.     onComplete:^(NSString *purchasedItemID) {
  35.        
  36.         [self unlockContentAssociatedWithPurchaseID:purchasedItemID];
  37.        
  38.     }
  39.      
  40.     onCancelled:^{
  41.        
  42.         //user canceled the transaction
  43.        
  44.     }];
  45. }
  46.  
  47. - (void)restoreAlreadyPurchasedContent {
  48.     NSString *MKStoreKitInfoPlistPath = [[NSBundle mainBundle] pathForResource:@"MKStoreKitConfigs" ofType:@"plist"];
  49.     NSDictionary *MKStoreKitDictionary = [NSDictionary dictionaryWithContentsOfFile:MKStoreKitInfoPlistPath];
  50.     NSArray *listOfPurchaseIDs = [MKStoreKitDictionary objectForKey:@"Non-Consumables"];
  51.     for (NSString *purchaseID in listOfPurchaseIDs) {
  52.         if ([MKStoreManager isFeaturePurchased:purchaseID] == YES) {
  53.             [self unlockContentAssociatedWithPurchaseID:purchaseID];            
  54.         }
  55.     }
  56. }
  57.  
  58. - (void)viewWillAppear:(BOOL)animated
  59. {
  60.     [super viewWillAppear:animated];
  61.     [self restoreAlreadyPurchasedContent];
  62. }
  63.  
  64. - (void)userPressedButtonToPurchasePartyPack {
  65.     if ([MKStoreManager isFeaturePurchased:kPartyPackPurchaseID] == NO) {
  66.         [self initiateTransactionForPurchaseID:kPartyPackPurchaseID];
  67.     }
  68. }
Add Comment
Please, Sign In to add comment