Permalink
Browse files

refact...

Signed-off-by: Marcio Mangar <marcio.mangar@gmail.com>
  • Loading branch information...
1 parent c8c3606 commit 6ef39aea9d0e8c62c01824d77b4196afb22d4708 @mangar committed Jan 23, 2013
@@ -18,13 +18,11 @@
54590A6416ADC8A100D84852 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 54590A6316ADC8A100D84852 /* Default-568h@2x.png */; };
54590A6716ADC8A100D84852 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 54590A6516ADC8A100D84852 /* MainStoryboard.storyboard */; };
54590A6A16ADC8A100D84852 /* mng_mcoolViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 54590A6916ADC8A100D84852 /* mng_mcoolViewController.m */; };
- 54590A7216ADE06D00D84852 /* InAppPurchaseManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 54590A7116ADE06D00D84852 /* InAppPurchaseManager.m */; };
54590A7416AF3F0A00D84852 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 54590A7316AF3F0A00D84852 /* Security.framework */; };
54590A7C16AF444100D84852 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 54590A7B16AF444100D84852 /* iAd.framework */; };
54590A7E16AF44C200D84852 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 54590A7D16AF44C200D84852 /* StoreKit.framework */; };
54F50B9B16B01C350034787F /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 54F50B9A16B01C350034787F /* Reachability.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
54F50B9D16B01C610034787F /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 54F50B9C16B01C610034787F /* SystemConfiguration.framework */; };
- 54F50BA016B029180034787F /* InAppRageIAPHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 54F50B9F16B029180034787F /* InAppRageIAPHelper.m */; };
54F50BA316B02A0C0034787F /* RageIAPHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 54F50BA216B02A0C0034787F /* RageIAPHelper.m */; };
C0DD158D16AF739A0024E7F8 /* IAPHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = C0DD158916AF739A0024E7F8 /* IAPHelper.m */; };
/* End PBXBuildFile section */
@@ -46,16 +44,12 @@
54590A6616ADC8A100D84852 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard.storyboard; sourceTree = "<group>"; };
54590A6816ADC8A100D84852 /* mng_mcoolViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mng_mcoolViewController.h; sourceTree = "<group>"; };
54590A6916ADC8A100D84852 /* mng_mcoolViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = mng_mcoolViewController.m; sourceTree = "<group>"; };
- 54590A7016ADE06D00D84852 /* InAppPurchaseManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InAppPurchaseManager.h; sourceTree = "<group>"; };
- 54590A7116ADE06D00D84852 /* InAppPurchaseManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InAppPurchaseManager.m; sourceTree = "<group>"; };
54590A7316AF3F0A00D84852 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
54590A7B16AF444100D84852 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; };
54590A7D16AF44C200D84852 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
54F50B9916B01C350034787F /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
54F50B9A16B01C350034787F /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };
54F50B9C16B01C610034787F /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
- 54F50B9E16B029180034787F /* InAppRageIAPHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = InAppRageIAPHelper.h; path = MCool/InAppRageIAPHelper.h; sourceTree = SOURCE_ROOT; };
- 54F50B9F16B029180034787F /* InAppRageIAPHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InAppRageIAPHelper.m; path = MCool/InAppRageIAPHelper.m; sourceTree = SOURCE_ROOT; };
54F50BA116B02A0C0034787F /* RageIAPHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RageIAPHelper.h; sourceTree = "<group>"; };
54F50BA216B02A0C0034787F /* RageIAPHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RageIAPHelper.m; sourceTree = "<group>"; };
C0DD158916AF739A0024E7F8 /* IAPHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IAPHelper.m; path = ../IAPHelper.m; sourceTree = "<group>"; };
@@ -121,8 +115,6 @@
54590A6816ADC8A100D84852 /* mng_mcoolViewController.h */,
54590A6916ADC8A100D84852 /* mng_mcoolViewController.m */,
54590A5416ADC8A100D84852 /* Supporting Files */,
- 54590A7016ADE06D00D84852 /* InAppPurchaseManager.h */,
- 54590A7116ADE06D00D84852 /* InAppPurchaseManager.m */,
);
path = MCool;
sourceTree = "<group>";
@@ -144,8 +136,6 @@
54F50B9816B01C350034787F /* Extra */ = {
isa = PBXGroup;
children = (
- 54F50B9E16B029180034787F /* InAppRageIAPHelper.h */,
- 54F50B9F16B029180034787F /* InAppRageIAPHelper.m */,
C0DD158A16AF739A0024E7F8 /* IAPHelper.h */,
C0DD158916AF739A0024E7F8 /* IAPHelper.m */,
54F50B9916B01C350034787F /* Reachability.h */,
@@ -226,10 +216,8 @@
54590A5A16ADC8A100D84852 /* main.m in Sources */,
54590A5E16ADC8A100D84852 /* mng_mcoolAppDelegate.m in Sources */,
54590A6A16ADC8A100D84852 /* mng_mcoolViewController.m in Sources */,
- 54590A7216ADE06D00D84852 /* InAppPurchaseManager.m in Sources */,
C0DD158D16AF739A0024E7F8 /* IAPHelper.m in Sources */,
54F50B9B16B01C350034787F /* Reachability.m in Sources */,
- 54F50BA016B029180034787F /* InAppRageIAPHelper.m in Sources */,
54F50BA316B02A0C0034787F /* RageIAPHelper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1,23 +0,0 @@
-#import <StoreKit/StoreKit.h>
-
-#define kInAppPurchaseManagerProductsFetchedNotification @"kInAppPurchaseManagerProductsFetchedNotification"
-
-//2
-#define kInAppPurchaseManagerTransactionFailedNotification @"kInAppPurchaseManagerTransactionFailedNotification"
-#define kInAppPurchaseManagerTransactionSucceededNotification @"kInAppPurchaseManagerTransactionSucceededNotification"
-
-
-
-@interface InAppPurchaseManager : NSObject <SKProductsRequestDelegate>
-{
- SKProduct *proUpgradeProduct;
- SKProductsRequest *productsRequest;
-}
-
-
-// 2
-- (void)loadStore;
-- (BOOL)canMakePurchases;
-- (void)purchaseProUpgrade;
-
-@end
@@ -1,210 +0,0 @@
-
-#import "InAppPurchaseManager.h"
-#import <StoreKit/StoreKit.h>
-
-//2
-#define kInAppPurchaseProUpgradeProductId @"mng.mcool.prod.15"
-
-
-
-@implementation InAppPurchaseManager
-
-
-#pragma -
-#pragma Public methods
-
-//
-// call this method once on startup
-//
-- (void)loadStore
-{
- // restarts any purchases if they were interrupted last time the app was open
- [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
-
- // get the product description (defined in early sections)
- [self requestProUpgradeProductData];
-}
-
-//
-// call this before making a purchase
-//
-- (BOOL)canMakePurchases
-{
- return [SKPaymentQueue canMakePayments];
-}
-
-//
-// kick off the upgrade transaction
-//
-- (void)purchaseProUpgrade
-{
- SKPayment *payment = [SKPayment paymentWithProductIdentifier:kInAppPurchaseProUpgradeProductId];
- [[SKPaymentQueue defaultQueue] addPayment:payment];
-}
-
-#pragma -
-#pragma Purchase helpers
-
-//
-// saves a record of the transaction by storing the receipt to disk
-//
-- (void)recordTransaction:(SKPaymentTransaction *)transaction
-{
- if ([transaction.payment.productIdentifier isEqualToString:kInAppPurchaseProUpgradeProductId])
- {
- // save the transaction receipt to disk
- [[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
-}
-
-//
-// enable pro features
-//
-- (void)provideContent:(NSString *)productId
-{
- if ([productId isEqualToString:kInAppPurchaseProUpgradeProductId])
- {
- // enable the pro features
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isProUpgradePurchased" ];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
-}
-
-//
-// removes the transaction from the queue and posts a notification with the transaction result
-//
-- (void)finishTransaction:(SKPaymentTransaction *)transaction wasSuccessful:(BOOL)wasSuccessful
-{
- // remove the transaction from the payment queue.
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
-
- NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:transaction, @"transaction" , nil];
- if (wasSuccessful)
- {
- // send out a notification that we’ve finished the transaction
- [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:userInfo];
- }
- else
- {
- // send out a notification for the failed transaction
- [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionFailedNotification object:self userInfo:userInfo];
- }
-}
-
-//
-// called when the transaction was successful
-//
-- (void)completeTransaction:(SKPaymentTransaction *)transaction
-{
- [self recordTransaction:transaction];
- [self provideContent:transaction.payment.productIdentifier];
- [self finishTransaction:transaction wasSuccessful:YES];
-}
-
-//
-// called when a transaction has been restored and and successfully completed
-//
-- (void)restoreTransaction:(SKPaymentTransaction *)transaction
-{
- [self recordTransaction:transaction.originalTransaction];
- [self provideContent:transaction.originalTransaction.payment.productIdentifier];
- [self finishTransaction:transaction wasSuccessful:YES];
-}
-
-//
-// called when a transaction has failed
-//
-- (void)failedTransaction:(SKPaymentTransaction *)transaction
-{
- if (transaction.error.code != SKErrorPaymentCancelled)
- {
- // error!
- [self finishTransaction:transaction wasSuccessful:NO];
- }
- else
- {
- // this is fine, the user just cancelled, so don’t notify
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
- }
-}
-
-#pragma mark -
-#pragma mark SKPaymentTransactionObserver methods
-
-//
-// called when the transaction status is updated
-//
-- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
-{
- for (SKPaymentTransaction *transaction in transactions)
- {
- switch (transaction.transactionState)
- {
- case SKPaymentTransactionStatePurchased:
- [self completeTransaction:transaction];
- break;
- case SKPaymentTransactionStateFailed:
- [self failedTransaction:transaction];
- break;
- case SKPaymentTransactionStateRestored:
- [self restoreTransaction:transaction];
- break;
- default:
- break;
- }
- }
-}
-
-
-
-- (void)requestProUpgradeProductData {
-
-
- NSSet *productIdentifiers = [NSSet setWithObject:@"mng.mcool.prod.15" ];
-
- productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
- productsRequest.delegate = self;
- [productsRequest start];
-
-
-}
-
-#pragma mark -
-#pragma mark SKProductsRequestDelegate methods
-
-- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
- NSArray *products = response.products;
-// proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain] : nil;
- proUpgradeProduct = [products count] == 1 ? [self firstObject:products] : nil;
- if (proUpgradeProduct)
- {
- NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
- NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
- NSLog(@"Product price: %@" , proUpgradeProduct.price);
- NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);
- }
-
- for (NSString *invalidProductId in response.invalidProductIdentifiers)
- {
- NSLog(@"Invalid product id: %@" , invalidProductId);
- }
-
- // finally release the reqest we alloc/init’ed in requestProUpgradeProductData
-// [productsRequest release];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
-}
-
-
-
-- (id)firstObject:(NSArray *)array {
- if ([array count] > 0) {
- return [array objectAtIndex:0];
- }
- return nil;
-}
-
-
-
-@end
@@ -1,18 +0,0 @@
-//
-// InAppRageIAPHelper.h
-// InAppRage
-//
-// Created by Ray Wenderlich on 2/28/11.
-// Copyright 2011 Ray Wenderlich. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-#import "IAPHelper.h"
-
-@interface InAppRageIAPHelper : IAPHelper {
-
-}
-
-+ (InAppRageIAPHelper *) sharedHelper;
-
-@end
@@ -1,37 +0,0 @@
-//
-// InAppRageIAPHelper.m
-// InAppRage
-//
-// Created by Ray Wenderlich on 2/28/11.
-// Copyright 2011 Ray Wenderlich. All rights reserved.
-//
-
-#import "InAppRageIAPHelper.h"
-
-@implementation InAppRageIAPHelper
-
-static InAppRageIAPHelper * _sharedHelper;
-
-+ (InAppRageIAPHelper *) sharedHelper {
-
- if (_sharedHelper != nil) {
- return _sharedHelper;
- }
- _sharedHelper = [[InAppRageIAPHelper alloc] init];
- return _sharedHelper;
-
-}
-
-- (id)init {
-
- NSSet *productIdentifiers = [NSSet setWithObjects:@"mng.mcool.prod.1", @"mng.mcool.prod.2", nil];
-
- if ((self = [super initWithProductIdentifiers:productIdentifiers])) {
-
- }
-
- return self;
-
-}
-
-@end

0 comments on commit 6ef39ae

Please sign in to comment.