Permalink
Browse files

made it a singleton

  • Loading branch information...
1 parent 77a3630 commit 391775bf1a74527a64c6c22c84a26a9cf8e99e1a @sobri909 committed May 21, 2012
Showing with 17 additions and 1 deletion.
  1. +4 −0 MGStoreKit.h
  2. +13 −1 MGStoreKit.m
View
4 MGStoreKit.h
@@ -14,6 +14,8 @@ typedef void (^PurchaseCallback)(NSString *productId);
@interface MGStoreKit : NSObject
<SKProductsRequestDelegate, SKPaymentTransactionObserver>
++ (MGStoreKit *)store;
+
// fetch products data
- (void)requestProductsData:(NSSet *)products
callback:(ProductsCallback)callback;
@@ -25,6 +27,8 @@ typedef void (^PurchaseCallback)(NSString *productId);
- (void)purchaseProduct:(NSString *)productId
success:(PurchaseCallback)callback
failed:(PurchaseCallback)failed;
+
+// restore previous purchases
- (void)restore:(ProductsCallback)callback;
@property (nonatomic, retain) NSMutableDictionary *cachedProducts;
View
14 MGStoreKit.m
@@ -19,16 +19,26 @@ @interface MGStoreKit ()
@implementation MGStoreKit
+static MGStoreKit *singleton;
+
@synthesize cachedProducts, productsRequest;
@synthesize productsCallback, purchaseCallback, failedCallback, restoreCallback;
++ (void)initialize {
+ singleton = [[MGStoreKit alloc] init];
+}
+
- (id)init {
self = [super init];
self.cachedProducts = [NSMutableDictionary dictionary];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
return self;
}
++ (MGStoreKit *)store {
+ return singleton;
+}
+
- (void)requestProductsData:(NSSet *)keys
callback:(ProductsCallback)callback {
BOOL haveAllCached = YES;
@@ -49,7 +59,9 @@ - (void)requestProductsData:(NSSet *)keys
self.productsRequest =
[[SKProductsRequest alloc] initWithProductIdentifiers:keys];
self.productsRequest.delegate = self;
- [self.productsRequest start];
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
+ [self.productsRequest start];
+ });
}
- (BOOL)canMakePayments {

0 comments on commit 391775b

Please sign in to comment.