From 9cc8cf0926347003aba3dcb710e64672da59bb23 Mon Sep 17 00:00:00 2001 From: Artem Date: Sun, 24 Mar 2024 15:53:01 +0100 Subject: [PATCH] Fixed build warnings #214 fixed deprecation warnings for NSURLSessionDataTask vs NSURLConnection --- .../RMStoreTransactionReceiptVerifier.m | 100 +++++++++--------- RMStore/RMStore.m | 16 ++- 2 files changed, 66 insertions(+), 50 deletions(-) diff --git a/RMStore/Optional/RMStoreTransactionReceiptVerifier.m b/RMStore/Optional/RMStoreTransactionReceiptVerifier.m index e95f73e1..9d0de89d 100644 --- a/RMStore/Optional/RMStoreTransactionReceiptVerifier.m +++ b/RMStore/Optional/RMStoreTransactionReceiptVerifier.m @@ -137,64 +137,66 @@ - (void)verifyRequestData:(NSData*)requestData request.HTTPBody = requestData; static NSString *requestMethod = @"POST"; request.HTTPMethod = requestMethod; - + dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - NSError *error; - NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error]; - dispatch_async(dispatch_get_main_queue(), ^{ - if (!data) - { - RMStoreLog(@"Server Connection Failed"); - 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")}]; - if (failureBlock != nil) + NSURLSessionDataTask* task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (!data) + { + RMStoreLog(@"Server Connection Failed"); + 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")}]; + if (failureBlock != nil) + { + failureBlock(wrapperError); + } + return; + } + NSError *jsonError; + NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; + if (!responseJSON) { - failureBlock(wrapperError); + RMStoreLog(@"Failed To Parse Server Response"); + if (failureBlock != nil) + { + failureBlock(jsonError); + } } - return; - } - NSError *jsonError; - NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; - if (!responseJSON) - { - RMStoreLog(@"Failed To Parse Server Response"); - if (failureBlock != nil) + + static NSString *statusKey = @"status"; + NSInteger statusCode = [responseJSON[statusKey] integerValue]; + + static NSInteger successCode = 0; + static NSInteger sandboxCode = 21007; + if (statusCode == successCode) { - failureBlock(jsonError); + if (successBlock != nil) + { + successBlock(); + } } - } - - static NSString *statusKey = @"status"; - NSInteger statusCode = [responseJSON[statusKey] integerValue]; - - static NSInteger successCode = 0; - static NSInteger sandboxCode = 21007; - if (statusCode == successCode) - { - if (successBlock != nil) + else if (statusCode == sandboxCode) { - successBlock(); + RMStoreLog(@"Verifying Sandbox Receipt"); + // From: https://developer.apple.com/library/ios/#technotes/tn2259/_index.html + // See also: http://stackoverflow.com/questions/9677193/ios-storekit-can-i-detect-when-im-in-the-sandbox + // 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. + + static NSString *sandboxURL = @"https://sandbox.itunes.apple.com/verifyReceipt"; + [self verifyRequestData:requestData url:sandboxURL success:successBlock failure:failureBlock]; } - } - else if (statusCode == sandboxCode) - { - RMStoreLog(@"Verifying Sandbox Receipt"); - // From: https://developer.apple.com/library/ios/#technotes/tn2259/_index.html - // See also: http://stackoverflow.com/questions/9677193/ios-storekit-can-i-detect-when-im-in-the-sandbox - // 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. - - static NSString *sandboxURL = @"https://sandbox.itunes.apple.com/verifyReceipt"; - [self verifyRequestData:requestData url:sandboxURL success:successBlock failure:failureBlock]; - } - else - { - RMStoreLog(@"Verification Failed With Code %ld", (long)statusCode); - NSError *serverError = [NSError errorWithDomain:RMStoreErrorDomain code:statusCode userInfo:nil]; - if (failureBlock != nil) + else { - failureBlock(serverError); + RMStoreLog(@"Verification Failed With Code %ld", (long)statusCode); + NSError *serverError = [NSError errorWithDomain:RMStoreErrorDomain code:statusCode userInfo:nil]; + if (failureBlock != nil) + { + failureBlock(serverError); + } } - } - }); + }); + }]; + + [task resume]; }); } diff --git a/RMStore/RMStore.m b/RMStore/RMStore.m index 1ea8d7ce..dee97a46 100755 --- a/RMStore/RMStore.m +++ b/RMStore/RMStore.m @@ -229,11 +229,19 @@ - (void)addPayment:(NSString*)productIdentifier payment.applicationUsername = userIdentifier; } +#ifdef DEBUG + if (@available(iOS 8.3, *)) { + payment.simulatesAskToBuyInSandbox = YES; + } +#endif + RMAddPaymentParameters *parameters = [[RMAddPaymentParameters alloc] init]; parameters.successBlock = successBlock; parameters.failureBlock = failureBlock; _addPaymentParameters[productIdentifier] = parameters; + NSLog(@"Begin store request: %@", NSStringFromClass([payment class])); + [[SKPaymentQueue defaultQueue] addPayment:payment]; } @@ -271,6 +279,9 @@ - (void)restoreTransactionsOnSuccess:(void (^)(NSArray *transactions))successBlo _restoredTransactions = [NSMutableArray array]; _restoreTransactionsSuccessBlock = successBlock; _restoreTransactionsFailureBlock = failureBlock; + + NSLog(@"Begin store request: %@", @"restoreCompletedTransactions"); + [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; } @@ -308,6 +319,9 @@ - (void)refreshReceiptOnSuccess:(RMStoreSuccessBlock)successBlock _refreshReceiptSuccessBlock = successBlock; _refreshReceiptRequest = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:@{}]; _refreshReceiptRequest.delegate = self; + + NSLog(@"Begin store request: %@", NSStringFromClass([_refreshReceiptRequest class])); + [_refreshReceiptRequest start]; } @@ -551,7 +565,7 @@ + (BOOL)hasPendingDownloadsInTransaction:(SKPaymentTransaction*)transaction - (void)didPurchaseTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQueue*)queue { RMStoreLog(@"transaction purchased with product %@", transaction.payment.productIdentifier); - + if (self.receiptVerifier != nil) { [self.receiptVerifier verifyTransaction:transaction success:^{