Skip to content

Commit f2ac9af

Browse files
ARC Related fixes
1 parent fbc43ff commit f2ac9af

6 files changed

+48
-86
lines changed

Externals/NSData+Base64.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,10 @@ - (NSString *)base64EncodedString
301301
NewBase64Encode([self bytes], [self length], true, &outputLength);
302302

303303
NSString *result =
304-
[[[NSString alloc]
304+
[[NSString alloc]
305305
initWithBytes:outputBuffer
306306
length:outputLength
307-
encoding:NSASCIIStringEncoding]
308-
autorelease];
307+
encoding:NSASCIIStringEncoding];
309308
free(outputBuffer);
310309
return result;
311310
}

MKSKProduct.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
@property (nonatomic, copy) void (^onReceiptVerificationSucceeded)();
3939
@property (nonatomic, copy) void (^onReceiptVerificationFailed)();
4040

41-
@property (nonatomic, retain) NSData *receipt;
41+
@property (nonatomic, strong) NSData *receipt;
4242

43-
@property (nonatomic, retain) NSString *productId;
44-
@property (nonatomic, retain) NSURLConnection *theConnection;
45-
@property (nonatomic, retain) NSMutableData *dataFromConnection;
43+
@property (nonatomic, strong) NSString *productId;
44+
@property (nonatomic, strong) NSURLConnection *theConnection;
45+
@property (nonatomic, strong) NSMutableData *dataFromConnection;
4646

4747
- (void) verifyReceiptOnComplete:(void (^)(void)) completionBlock
4848
onError:(void (^)(NSError*)) errorBlock;

MKSKProduct.m

+13-21
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,21 @@ +(void) verifyProductForReviewAccess:(NSString*) productId
6666
{
6767
if(REVIEW_ALLOWED)
6868
{
69-
[onReviewRequestVerificationSucceeded release];
70-
onReviewRequestVerificationSucceeded = [completionBlock copy];
71-
72-
[onReviewRequestVerificationFailed release];
69+
onReviewRequestVerificationSucceeded = [completionBlock copy];
7370
onReviewRequestVerificationFailed = [errorBlock copy];
7471

75-
UIDevice *dev = [UIDevice currentDevice];
72+
UIDevice *dev = [UIDevice currentDevice];
7673
NSString *uniqueID;
7774
if ([dev respondsToSelector:@selector(uniqueIdentifier)])
78-
uniqueID = dev.uniqueIdentifier;
75+
uniqueID = [dev valueForKey:@"uniqueIdentifier"];
7976
else {
8077
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
8178
id uuid = [defaults objectForKey:@"uniqueID"];
8279
if (uuid)
8380
uniqueID = (NSString *)uuid;
8481
else {
8582
CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
86-
uniqueID = (NSString *)cfUuid;
83+
uniqueID = (__bridge NSString *)cfUuid;
8784
CFRelease(cfUuid);
8885
[defaults setObject:uniqueID forKey:@"uniqueID"];
8986
}
@@ -134,7 +131,6 @@ - (void) verifyReceiptOnComplete:(void (^)(void)) completionBlock
134131
encoding:NSASCIIStringEncoding];
135132

136133
NSString *postData = [NSString stringWithFormat:@"receiptdata=%@", receiptDataString];
137-
[receiptDataString release];
138134

139135
NSString *length = [NSString stringWithFormat:@"%d", [postData length]];
140136
[theRequest setValue:length forHTTPHeaderField:@"Content-Length"];
@@ -163,9 +159,8 @@ - (void)connection:(NSURLConnection *)connection
163159

164160
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
165161
{
166-
NSString *responseString = [[[NSString alloc] initWithData:self.dataFromConnection
167-
encoding:NSASCIIStringEncoding]
168-
autorelease];
162+
NSString *responseString = [[NSString alloc] initWithData:self.dataFromConnection
163+
encoding:NSASCIIStringEncoding];
169164

170165
self.dataFromConnection = nil;
171166

@@ -186,7 +181,6 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
186181
}
187182
}
188183

189-
[responseString release];
190184

191185
}
192186

@@ -219,41 +213,39 @@ + (void)connection:(NSURLConnection *)connection
219213

220214
+ (void)connectionDidFinishLoading:(NSURLConnection *)connection
221215
{
222-
NSString *responseString = [[[NSString alloc] initWithData:sDataFromConnection
223-
encoding:NSASCIIStringEncoding]
224-
autorelease];
216+
NSString *responseString = [[NSString alloc] initWithData:sDataFromConnection
217+
encoding:NSASCIIStringEncoding];
225218

226-
[sDataFromConnection release], sDataFromConnection = nil;
219+
sDataFromConnection = nil;
227220

228221
if([responseString isEqualToString:@"YES"])
229222
{
230223
if(onReviewRequestVerificationSucceeded)
231224
{
232225
onReviewRequestVerificationSucceeded();
233-
[onReviewRequestVerificationSucceeded release], onReviewRequestVerificationFailed = nil;
226+
onReviewRequestVerificationFailed = nil;
234227
}
235228
}
236229
else
237230
{
238231
if(onReviewRequestVerificationFailed)
239232
onReviewRequestVerificationFailed(nil);
240233

241-
[onReviewRequestVerificationFailed release], onReviewRequestVerificationFailed = nil;
234+
onReviewRequestVerificationFailed = nil;
242235
}
243236

244-
[responseString release];
245237

246238
}
247239

248240
+ (void)connection:(NSURLConnection *)connection
249241
didFailWithError:(NSError *)error
250242
{
251-
[sDataFromConnection release], sDataFromConnection = nil;
243+
sDataFromConnection = nil;
252244

253245
if(onReviewRequestVerificationFailed)
254246
{
255247
onReviewRequestVerificationFailed(nil);
256-
[onReviewRequestVerificationFailed release], onReviewRequestVerificationFailed = nil;
248+
onReviewRequestVerificationFailed = nil;
257249
}
258250
}
259251
@end

MKSKSubscriptionProduct.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838

3939
@property (nonatomic, copy) void (^onSubscriptionVerificationFailed)();
4040
@property (nonatomic, copy) void (^onSubscriptionVerificationCompleted)(NSNumber* isActive);
41-
@property (nonatomic, retain) NSData *receipt;
42-
@property (nonatomic, retain) NSDictionary *verifiedReceiptDictionary;
41+
@property (nonatomic, strong) NSData *receipt;
42+
@property (nonatomic, strong) NSDictionary *verifiedReceiptDictionary;
4343
@property (nonatomic, assign) int subscriptionDays;
44-
@property (nonatomic, retain) NSString *productId;
45-
@property (nonatomic, retain) NSURLConnection *theConnection;
46-
@property (nonatomic, retain) NSMutableData *dataFromConnection;
44+
@property (nonatomic, strong) NSString *productId;
45+
@property (nonatomic, strong) NSURLConnection *theConnection;
46+
@property (nonatomic, strong) NSMutableData *dataFromConnection;
4747

4848

4949
- (void) verifyReceiptOnComplete:(void (^)(NSNumber*)) completionBlock

MKSKSubscriptionProduct.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,12 @@ -(BOOL) isSubscriptionActive
9393

9494
//2011-07-03 05:31:55 Etc/GMT
9595
purchasedDateString = [purchasedDateString stringByReplacingOccurrencesOfString:@" Etc/GMT" withString:@""];
96-
NSLocale *POSIXLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
96+
NSLocale *POSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
9797
[df setLocale:POSIXLocale];
9898
[df setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
9999
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
100100

101101
NSDate *purchasedDate = [df dateFromString: purchasedDateString];
102-
[df release];
103102

104103
int numberOfDays = [purchasedDate timeIntervalSinceNow] / (-86400.0);
105104
return (self.subscriptionDays > numberOfDays);
@@ -123,7 +122,7 @@ - (void)connection:(NSURLConnection *)connection
123122

124123
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
125124
{
126-
self.verifiedReceiptDictionary = [[[self.dataFromConnection copy] autorelease] objectFromJSONData];
125+
self.verifiedReceiptDictionary = [[self.dataFromConnection copy] objectFromJSONData];
127126
if(self.onSubscriptionVerificationCompleted)
128127
{
129128
self.onSubscriptionVerificationCompleted([NSNumber numberWithBool:[self isSubscriptionActive]]);

MKStoreManager.m

+22-50
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ @interface MKStoreManager () //private methods and properties
4646
@property (nonatomic, copy) void (^onRestoreFailed)(NSError* error);
4747
@property (nonatomic, copy) void (^onRestoreCompleted)();
4848

49-
@property (nonatomic, retain) NSMutableArray *purchasableObjects;
50-
@property (nonatomic, retain) NSMutableDictionary *subscriptionProducts;
49+
@property (nonatomic, strong) NSMutableArray *purchasableObjects;
50+
@property (nonatomic, strong) NSMutableDictionary *subscriptionProducts;
5151

52-
@property (nonatomic, retain) MKStoreObserver *storeObserver;
52+
@property (nonatomic, strong) MKStoreObserver *storeObserver;
5353
@property (nonatomic, assign, getter=isProductsAvailable) BOOL isProductsAvailable;
5454

5555
- (void) requestProductData;
@@ -109,18 +109,17 @@ +(BOOL) iCloudAvailable {
109109

110110
- (void)dealloc {
111111

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;
119118
}
120119

121120
+ (void) dealloc
122121
{
123-
[_sharedStoreManager release], _sharedStoreManager = nil;
122+
_sharedStoreManager = nil;
124123
[super dealloc];
125124
}
126125

@@ -129,7 +128,7 @@ +(void) setObject:(id) object forKey:(NSString*) key
129128
NSString *objectString = nil;
130129
if([object isKindOfClass:[NSData class]])
131130
{
132-
objectString = [[[NSString alloc] initWithData:object encoding:NSUTF8StringEncoding] autorelease];
131+
objectString = [[NSString alloc] initWithData:object encoding:NSUTF8StringEncoding];
133132
}
134133
if([object isKindOfClass:[NSNumber class]])
135134
{
@@ -216,29 +215,6 @@ - (id)copyWithZone:(NSZone *)zone
216215
return self;
217216
}
218217

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-
242218
#pragma mark Internal MKStoreKit functions
243219

244220
-(NSDictionary*) storeKitItems
@@ -326,18 +302,14 @@ - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu
326302
for(NSString *invalidProduct in response.invalidProductIdentifiers)
327303
NSLog(@"Problem in iTunes connect configuration for product: %@", invalidProduct);
328304
#endif
329-
330-
[request autorelease];
331-
305+
332306
isProductsAvailable = YES;
333307
[[NSNotificationCenter defaultCenter] postNotificationName:kProductFetchedNotification
334308
object:[NSNumber numberWithBool:isProductsAvailable]];
335309
}
336310

337311
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error
338312
{
339-
[request autorelease];
340-
341313
isProductsAvailable = NO;
342314
[[NSNotificationCenter defaultCenter] postNotificationName:kProductFetchedNotification
343315
object:[NSNumber numberWithBool:isProductsAvailable]];
@@ -370,7 +342,6 @@ - (NSMutableArray*) purchasableObjectsDescription
370342
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
371343
[numberFormatter setLocale:product.priceLocale];
372344
NSString *formattedString = [numberFormatter stringFromNumber:product.price];
373-
[numberFormatter release];
374345

375346
// you might probably need to change this line to suit your UI needs
376347
NSString *description = [NSString stringWithFormat:@"%@ (%@)",[product localizedTitle], formattedString];
@@ -381,7 +352,6 @@ - (NSMutableArray*) purchasableObjectsDescription
381352
[productDescriptions addObject: description];
382353
}
383354

384-
[productDescriptions autorelease];
385355
return productDescriptions;
386356
}
387357

@@ -405,7 +375,6 @@ - (NSMutableDictionary *)pricesDictionary {
405375
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
406376
[numberFormatter setLocale:product.priceLocale];
407377
NSString *formattedString = [numberFormatter stringFromNumber:product.price];
408-
[numberFormatter release];
409378

410379
NSString *priceString = [NSString stringWithFormat:@"%@", formattedString];
411380
[priceDict setObject:priceString forKey:product.productIdentifier];
@@ -432,7 +401,6 @@ - (void) buyFeature:(NSString*) featureId
432401
cancelButtonTitle:NSLocalizedString(@"Dismiss", @"")
433402
otherButtonTitles:nil];
434403
[alert show];
435-
[alert release];
436404

437405
if(self.onTransactionCompleted)
438406
self.onTransactionCompleted(featureId);
@@ -454,7 +422,13 @@ -(void) addToQueue:(NSString*) productId
454422
{
455423
if ([SKPaymentQueue canMakePayments])
456424
{
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];
458432
[[SKPaymentQueue defaultQueue] addPayment:payment];
459433
}
460434
else
@@ -465,7 +439,6 @@ -(void) addToQueue:(NSString*) productId
465439
cancelButtonTitle:NSLocalizedString(@"Dismiss", @"")
466440
otherButtonTitles: nil];
467441
[alert show];
468-
[alert release];
469442
}
470443
}
471444

@@ -505,7 +478,7 @@ - (void) startVerifyingSubscriptionReceipts
505478
self.subscriptionProducts = [NSMutableDictionary dictionary];
506479
for(NSString *productId in [subscriptions allKeys])
507480
{
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]];
509482
product.receipt = [MKStoreManager dataForKey:productId]; // cached receipt
510483

511484
if(product.receipt)
@@ -562,7 +535,7 @@ -(void) provideContent: (NSString*) productIdentifier
562535
// ping server and get response before serializing the product
563536
// this is a blocking call to post receipt data to your server
564537
// 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];
566539

567540
[thisProduct verifyReceiptOnComplete:^
568541
{
@@ -602,7 +575,7 @@ -(void) rememberPurchaseOfProduct:(NSString*) productIdentifier
602575
int oldCount = [[MKStoreManager numberForKey:productPurchased] intValue];
603576
int newCount = oldCount + quantityPurchased;
604577

605-
[MKStoreManager setObject:[NSNumber numberWithInt:newCount] forKey:productPurchased];
578+
[MKStoreManager setObject:[NSNumber numberWithInt:newCount] forKey:productIdentifier];
606579
}
607580
else
608581
{
@@ -636,7 +609,6 @@ - (void) failedTransaction: (SKPaymentTransaction *)transaction
636609
cancelButtonTitle:NSLocalizedString(@"Dismiss", @"")
637610
otherButtonTitles: nil];
638611
[alert show];
639-
[alert release];
640612

641613
if(self.onTransactionCancelled)
642614
self.onTransactionCancelled();

0 commit comments

Comments
 (0)