Skip to content

Commit 9cc8cf0

Browse files
committed
Fixed build warnings robotmedia#214
fixed deprecation warnings for NSURLSessionDataTask vs NSURLConnection
1 parent 48281e2 commit 9cc8cf0

File tree

2 files changed

+66
-50
lines changed

2 files changed

+66
-50
lines changed

RMStore/Optional/RMStoreTransactionReceiptVerifier.m

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -137,64 +137,66 @@ - (void)verifyRequestData:(NSData*)requestData
137137
request.HTTPBody = requestData;
138138
static NSString *requestMethod = @"POST";
139139
request.HTTPMethod = requestMethod;
140-
140+
141141
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
142-
NSError *error;
143-
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
144-
dispatch_async(dispatch_get_main_queue(), ^{
145-
if (!data)
146-
{
147-
RMStoreLog(@"Server Connection Failed");
148-
NSError *wrapperError = [NSError errorWithDomain:RMStoreErrorDomain code:RMStoreErrorCodeUnableToCompleteVerification userInfo:@{NSUnderlyingErrorKey : error, NSLocalizedDescriptionKey : NSLocalizedStringFromTable(@"Connection to Apple failed. Check the underlying error for more info.", @"RMStore", @"Error description")}];
149-
if (failureBlock != nil)
142+
NSURLSessionDataTask* task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
143+
dispatch_async(dispatch_get_main_queue(), ^{
144+
if (!data)
145+
{
146+
RMStoreLog(@"Server Connection Failed");
147+
NSError *wrapperError = [NSError errorWithDomain:RMStoreErrorDomain code:RMStoreErrorCodeUnableToCompleteVerification userInfo:@{NSUnderlyingErrorKey : error, NSLocalizedDescriptionKey : NSLocalizedStringFromTable(@"Connection to Apple failed. Check the underlying error for more info.", @"RMStore", @"Error description")}];
148+
if (failureBlock != nil)
149+
{
150+
failureBlock(wrapperError);
151+
}
152+
return;
153+
}
154+
NSError *jsonError;
155+
NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
156+
if (!responseJSON)
150157
{
151-
failureBlock(wrapperError);
158+
RMStoreLog(@"Failed To Parse Server Response");
159+
if (failureBlock != nil)
160+
{
161+
failureBlock(jsonError);
162+
}
152163
}
153-
return;
154-
}
155-
NSError *jsonError;
156-
NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
157-
if (!responseJSON)
158-
{
159-
RMStoreLog(@"Failed To Parse Server Response");
160-
if (failureBlock != nil)
164+
165+
static NSString *statusKey = @"status";
166+
NSInteger statusCode = [responseJSON[statusKey] integerValue];
167+
168+
static NSInteger successCode = 0;
169+
static NSInteger sandboxCode = 21007;
170+
if (statusCode == successCode)
161171
{
162-
failureBlock(jsonError);
172+
if (successBlock != nil)
173+
{
174+
successBlock();
175+
}
163176
}
164-
}
165-
166-
static NSString *statusKey = @"status";
167-
NSInteger statusCode = [responseJSON[statusKey] integerValue];
168-
169-
static NSInteger successCode = 0;
170-
static NSInteger sandboxCode = 21007;
171-
if (statusCode == successCode)
172-
{
173-
if (successBlock != nil)
177+
else if (statusCode == sandboxCode)
174178
{
175-
successBlock();
179+
RMStoreLog(@"Verifying Sandbox Receipt");
180+
// From: https://developer.apple.com/library/ios/#technotes/tn2259/_index.html
181+
// See also: http://stackoverflow.com/questions/9677193/ios-storekit-can-i-detect-when-im-in-the-sandbox
182+
// Always verify your receipt first with the production URL; proceed to verify with the sandbox URL if you receive a 21007 status code. Following this approach ensures that you do not have to switch between URLs while your application is being tested or reviewed in the sandbox or is live in the App Store.
183+
184+
static NSString *sandboxURL = @"https://sandbox.itunes.apple.com/verifyReceipt";
185+
[self verifyRequestData:requestData url:sandboxURL success:successBlock failure:failureBlock];
176186
}
177-
}
178-
else if (statusCode == sandboxCode)
179-
{
180-
RMStoreLog(@"Verifying Sandbox Receipt");
181-
// From: https://developer.apple.com/library/ios/#technotes/tn2259/_index.html
182-
// See also: http://stackoverflow.com/questions/9677193/ios-storekit-can-i-detect-when-im-in-the-sandbox
183-
// Always verify your receipt first with the production URL; proceed to verify with the sandbox URL if you receive a 21007 status code. Following this approach ensures that you do not have to switch between URLs while your application is being tested or reviewed in the sandbox or is live in the App Store.
184-
185-
static NSString *sandboxURL = @"https://sandbox.itunes.apple.com/verifyReceipt";
186-
[self verifyRequestData:requestData url:sandboxURL success:successBlock failure:failureBlock];
187-
}
188-
else
189-
{
190-
RMStoreLog(@"Verification Failed With Code %ld", (long)statusCode);
191-
NSError *serverError = [NSError errorWithDomain:RMStoreErrorDomain code:statusCode userInfo:nil];
192-
if (failureBlock != nil)
187+
else
193188
{
194-
failureBlock(serverError);
189+
RMStoreLog(@"Verification Failed With Code %ld", (long)statusCode);
190+
NSError *serverError = [NSError errorWithDomain:RMStoreErrorDomain code:statusCode userInfo:nil];
191+
if (failureBlock != nil)
192+
{
193+
failureBlock(serverError);
194+
}
195195
}
196-
}
197-
});
196+
});
197+
}];
198+
199+
[task resume];
198200
});
199201
}
200202

RMStore/RMStore.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,19 @@ - (void)addPayment:(NSString*)productIdentifier
229229
payment.applicationUsername = userIdentifier;
230230
}
231231

232+
#ifdef DEBUG
233+
if (@available(iOS 8.3, *)) {
234+
payment.simulatesAskToBuyInSandbox = YES;
235+
}
236+
#endif
237+
232238
RMAddPaymentParameters *parameters = [[RMAddPaymentParameters alloc] init];
233239
parameters.successBlock = successBlock;
234240
parameters.failureBlock = failureBlock;
235241
_addPaymentParameters[productIdentifier] = parameters;
236242

243+
NSLog(@"Begin store request: %@", NSStringFromClass([payment class]));
244+
237245
[[SKPaymentQueue defaultQueue] addPayment:payment];
238246
}
239247

@@ -271,6 +279,9 @@ - (void)restoreTransactionsOnSuccess:(void (^)(NSArray *transactions))successBlo
271279
_restoredTransactions = [NSMutableArray array];
272280
_restoreTransactionsSuccessBlock = successBlock;
273281
_restoreTransactionsFailureBlock = failureBlock;
282+
283+
NSLog(@"Begin store request: %@", @"restoreCompletedTransactions");
284+
274285
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
275286
}
276287

@@ -308,6 +319,9 @@ - (void)refreshReceiptOnSuccess:(RMStoreSuccessBlock)successBlock
308319
_refreshReceiptSuccessBlock = successBlock;
309320
_refreshReceiptRequest = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:@{}];
310321
_refreshReceiptRequest.delegate = self;
322+
323+
NSLog(@"Begin store request: %@", NSStringFromClass([_refreshReceiptRequest class]));
324+
311325
[_refreshReceiptRequest start];
312326
}
313327

@@ -551,7 +565,7 @@ + (BOOL)hasPendingDownloadsInTransaction:(SKPaymentTransaction*)transaction
551565
- (void)didPurchaseTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQueue*)queue
552566
{
553567
RMStoreLog(@"transaction purchased with product %@", transaction.payment.productIdentifier);
554-
568+
555569
if (self.receiptVerifier != nil)
556570
{
557571
[self.receiptVerifier verifyTransaction:transaction success:^{

0 commit comments

Comments
 (0)