@@ -46,10 +46,10 @@ @interface MKStoreManager () //private methods and properties
46
46
@property (nonatomic , copy ) void (^onRestoreFailed)(NSError * error);
47
47
@property (nonatomic , copy ) void (^onRestoreCompleted)();
48
48
49
- @property (nonatomic , retain ) NSMutableArray *purchasableObjects;
50
- @property (nonatomic , retain ) NSMutableDictionary *subscriptionProducts;
49
+ @property (nonatomic , strong ) NSMutableArray *purchasableObjects;
50
+ @property (nonatomic , strong ) NSMutableDictionary *subscriptionProducts;
51
51
52
- @property (nonatomic , retain ) MKStoreObserver *storeObserver;
52
+ @property (nonatomic , strong ) MKStoreObserver *storeObserver;
53
53
@property (nonatomic , assign , getter =isProductsAvailable) BOOL isProductsAvailable;
54
54
55
55
- (void ) requestProductData ;
@@ -109,18 +109,17 @@ +(BOOL) iCloudAvailable {
109
109
110
110
- (void )dealloc {
111
111
112
- [_purchasableObjects release ], _purchasableObjects = nil ;
113
- [_storeObserver release ], _storeObserver = nil ;
114
- [onTransactionCancelled release ], onTransactionCancelled = nil ;
115
- [onTransactionCompleted release ], onTransactionCompleted = nil ;
116
- [onRestoreFailed release ], onRestoreFailed = nil ;
117
- [onRestoreCompleted release ], onRestoreCompleted = nil ;
118
- [super dealloc ];
112
+ _purchasableObjects = nil ;
113
+ _storeObserver = nil ;
114
+ onTransactionCancelled = nil ;
115
+ onTransactionCompleted = nil ;
116
+ onRestoreFailed = nil ;
117
+ onRestoreCompleted = nil ;
119
118
}
120
119
121
120
+ (void ) dealloc
122
121
{
123
- [_sharedStoreManager release ], _sharedStoreManager = nil ;
122
+ _sharedStoreManager = nil ;
124
123
[super dealloc ];
125
124
}
126
125
@@ -129,7 +128,7 @@ +(void) setObject:(id) object forKey:(NSString*) key
129
128
NSString *objectString = nil ;
130
129
if ([object isKindOfClass: [NSData class ]])
131
130
{
132
- objectString = [[[ NSString alloc ] initWithData: object encoding: NSUTF8StringEncoding] autorelease ];
131
+ objectString = [[NSString alloc ] initWithData: object encoding: NSUTF8StringEncoding];
133
132
}
134
133
if ([object isKindOfClass: [NSNumber class ]])
135
134
{
@@ -216,29 +215,6 @@ - (id)copyWithZone:(NSZone *)zone
216
215
return self;
217
216
}
218
217
219
- #if __has_feature (objc_arc)
220
-
221
- - (id )retain
222
- {
223
- return self;
224
- }
225
-
226
- - (unsigned )retainCount
227
- {
228
- return UINT_MAX; // denotes an object that cannot be released
229
- }
230
-
231
- - (void )release
232
- {
233
- // do nothing
234
- }
235
-
236
- - (id )autorelease
237
- {
238
- return self;
239
- }
240
- #endif
241
-
242
218
#pragma mark Internal MKStoreKit functions
243
219
244
220
-(NSDictionary *) storeKitItems
@@ -326,18 +302,14 @@ - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu
326
302
for (NSString *invalidProduct in response.invalidProductIdentifiers )
327
303
NSLog (@" Problem in iTunes connect configuration for product: %@ " , invalidProduct);
328
304
#endif
329
-
330
- [request autorelease ];
331
-
305
+
332
306
isProductsAvailable = YES ;
333
307
[[NSNotificationCenter defaultCenter ] postNotificationName: kProductFetchedNotification
334
308
object: [NSNumber numberWithBool: isProductsAvailable]];
335
309
}
336
310
337
311
- (void )request : (SKRequest *)request didFailWithError : (NSError *)error
338
312
{
339
- [request autorelease ];
340
-
341
313
isProductsAvailable = NO ;
342
314
[[NSNotificationCenter defaultCenter ] postNotificationName: kProductFetchedNotification
343
315
object: [NSNumber numberWithBool: isProductsAvailable]];
@@ -370,7 +342,6 @@ - (NSMutableArray*) purchasableObjectsDescription
370
342
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
371
343
[numberFormatter setLocale: product.priceLocale];
372
344
NSString *formattedString = [numberFormatter stringFromNumber: product.price];
373
- [numberFormatter release ];
374
345
375
346
// you might probably need to change this line to suit your UI needs
376
347
NSString *description = [NSString stringWithFormat: @" %@ (%@ )" ,[product localizedTitle ], formattedString];
@@ -381,7 +352,6 @@ - (NSMutableArray*) purchasableObjectsDescription
381
352
[productDescriptions addObject: description];
382
353
}
383
354
384
- [productDescriptions autorelease ];
385
355
return productDescriptions;
386
356
}
387
357
@@ -405,7 +375,6 @@ - (NSMutableDictionary *)pricesDictionary {
405
375
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
406
376
[numberFormatter setLocale: product.priceLocale];
407
377
NSString *formattedString = [numberFormatter stringFromNumber: product.price];
408
- [numberFormatter release ];
409
378
410
379
NSString *priceString = [NSString stringWithFormat: @" %@ " , formattedString];
411
380
[priceDict setObject: priceString forKey: product.productIdentifier];
@@ -432,7 +401,6 @@ - (void) buyFeature:(NSString*) featureId
432
401
cancelButtonTitle: NSLocalizedString(@" Dismiss" , @" " )
433
402
otherButtonTitles: nil ];
434
403
[alert show ];
435
- [alert release ];
436
404
437
405
if (self.onTransactionCompleted )
438
406
self.onTransactionCompleted (featureId);
@@ -454,7 +422,13 @@ -(void) addToQueue:(NSString*) productId
454
422
{
455
423
if ([SKPaymentQueue canMakePayments ])
456
424
{
457
- SKPayment *payment = [SKPayment paymentWithProductIdentifier: productId];
425
+ NSArray *allIds = [self .purchasableObjects valueForKey: @" productIdentifier" ];
426
+ int index = [allIds indexOfObject: productId];
427
+
428
+ if (index == NSNotFound ) return ;
429
+
430
+ SKProduct *thisProduct = [self .purchasableObjects objectAtIndex: index ];
431
+ SKPayment *payment = [SKPayment paymentWithProduct: thisProduct];
458
432
[[SKPaymentQueue defaultQueue ] addPayment: payment];
459
433
}
460
434
else
@@ -465,7 +439,6 @@ -(void) addToQueue:(NSString*) productId
465
439
cancelButtonTitle: NSLocalizedString(@" Dismiss" , @" " )
466
440
otherButtonTitles: nil ];
467
441
[alert show ];
468
- [alert release ];
469
442
}
470
443
}
471
444
@@ -505,7 +478,7 @@ - (void) startVerifyingSubscriptionReceipts
505
478
self.subscriptionProducts = [NSMutableDictionary dictionary ];
506
479
for (NSString *productId in [subscriptions allKeys ])
507
480
{
508
- MKSKSubscriptionProduct *product = [[[ MKSKSubscriptionProduct alloc ] initWithProductId: productId subscriptionDays: [[subscriptions objectForKey: productId] intValue ]] autorelease ];
481
+ MKSKSubscriptionProduct *product = [[MKSKSubscriptionProduct alloc ] initWithProductId: productId subscriptionDays: [[subscriptions objectForKey: productId] intValue ]];
509
482
product.receipt = [MKStoreManager dataForKey: productId]; // cached receipt
510
483
511
484
if (product.receipt )
@@ -562,7 +535,7 @@ -(void) provideContent: (NSString*) productIdentifier
562
535
// ping server and get response before serializing the product
563
536
// this is a blocking call to post receipt data to your server
564
537
// it should normally take a couple of seconds on a good 3G connection
565
- MKSKProduct *thisProduct = [[[ MKSKProduct alloc ] initWithProductId: productIdentifier receiptData: receiptData] autorelease ];
538
+ MKSKProduct *thisProduct = [[MKSKProduct alloc ] initWithProductId: productIdentifier receiptData: receiptData];
566
539
567
540
[thisProduct verifyReceiptOnComplete: ^
568
541
{
@@ -602,7 +575,7 @@ -(void) rememberPurchaseOfProduct:(NSString*) productIdentifier
602
575
int oldCount = [[MKStoreManager numberForKey: productPurchased] intValue ];
603
576
int newCount = oldCount + quantityPurchased;
604
577
605
- [MKStoreManager setObject: [NSNumber numberWithInt: newCount] forKey: productPurchased ];
578
+ [MKStoreManager setObject: [NSNumber numberWithInt: newCount] forKey: productIdentifier ];
606
579
}
607
580
else
608
581
{
@@ -636,7 +609,6 @@ - (void) failedTransaction: (SKPaymentTransaction *)transaction
636
609
cancelButtonTitle: NSLocalizedString(@" Dismiss" , @" " )
637
610
otherButtonTitles: nil ];
638
611
[alert show ];
639
- [alert release ];
640
612
641
613
if (self.onTransactionCancelled )
642
614
self.onTransactionCancelled ();
0 commit comments