-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix to ensure restoreTransactions completion callback is called #150
Open
SeanBlahovici
wants to merge
21
commits into
robotmedia:master
Choose a base branch
from
SeanBlahovici:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d448533
Added MutableSet instead of regular counter to insure that callback i…
67bf17b
Updating version podspec
b3f8822
Updating podspec source
1396cbb
Forgot nil check on producit Id for the set
858fb43
Reverting to origin podspec for pull request
ddab329
Merge pull request #169 from gitter-badger/gitter-badge
hpique 303b1e9
Update README.md
hpique 3153a69
Fixed wrong formatting and changed description in podspec
d1737ca
Fixed another auto format problem
811d820
Removing remaining new lines
2d493ee
Did a proper compare to the latest version of RMStore. Reset all form…
344a5d7
Added MutableSet instead of regular counter to insure that callback i…
58c63e4
Updating version podspec
86bc310
Updating podspec source
576560f
Forgot nil check on producit Id for the set
551a7e2
Reverting to origin podspec for pull request
968349b
Fixed wrong formatting and changed description in podspec
a7e52f0
Removing remaining new lines
6a35cf8
Did a proper compare to the latest version of RMStore. Reset all form…
fc805bd
Merged Master into fork. Hopefully this will allow the Pull Request t…
d548cd8
Merge remote-tracking branch 'origin/master' into github_master
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,16 +133,15 @@ @implementation RMStore { | |
NSMutableDictionary *_addPaymentParameters; // HACK: We use a dictionary of product identifiers because the returned SKPayment is different from the one we add to the queue. Bad Apple. | ||
NSMutableDictionary *_products; | ||
NSMutableSet *_productsRequestDelegates; | ||
|
||
NSMutableArray *_restoredTransactions; | ||
|
||
NSInteger _pendingRestoredTransactionsCount; | ||
NSMutableSet *_pendingRestoredTransactionIds; | ||
BOOL _restoredCompletedTransactionsFinished; | ||
|
||
SKReceiptRefreshRequest *_refreshReceiptRequest; | ||
void (^_refreshReceiptFailureBlock)(NSError* error); | ||
void (^_refreshReceiptSuccessBlock)(); | ||
|
||
void (^_restoreTransactionsFailureBlock)(NSError* error); | ||
void (^_restoreTransactionsSuccessBlock)(NSArray* transactions); | ||
} | ||
|
@@ -155,6 +154,7 @@ - (instancetype) init | |
_products = [NSMutableDictionary dictionary]; | ||
_productsRequestDelegates = [NSMutableSet set]; | ||
_restoredTransactions = [NSMutableArray array]; | ||
_pendingRestoredTransactionIds = [NSMutableSet set]; | ||
[[SKPaymentQueue defaultQueue] addTransactionObserver:self]; | ||
} | ||
return self; | ||
|
@@ -215,12 +215,12 @@ - (void)addPayment:(NSString*)productIdentifier | |
{ | ||
payment.applicationUsername = userIdentifier; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
RMAddPaymentParameters *parameters = [[RMAddPaymentParameters alloc] init]; | ||
parameters.successBlock = successBlock; | ||
parameters.failureBlock = failureBlock; | ||
_addPaymentParameters[productIdentifier] = parameters; | ||
|
||
[[SKPaymentQueue defaultQueue] addPayment:payment]; | ||
} | ||
|
||
|
@@ -238,10 +238,10 @@ - (void)requestProducts:(NSSet*)identifiers | |
delegate.successBlock = successBlock; | ||
delegate.failureBlock = failureBlock; | ||
[_productsRequestDelegates addObject:delegate]; | ||
|
||
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:identifiers]; | ||
productsRequest.delegate = delegate; | ||
|
||
[productsRequest start]; | ||
} | ||
|
||
|
@@ -254,7 +254,7 @@ - (void)restoreTransactionsOnSuccess:(void (^)(NSArray *transactions))successBlo | |
failure:(void (^)(NSError *error))failureBlock | ||
{ | ||
_restoredCompletedTransactionsFinished = NO; | ||
_pendingRestoredTransactionsCount = 0; | ||
[_pendingRestoredTransactionIds removeAllObjects]; | ||
_restoredTransactions = [NSMutableArray array]; | ||
_restoreTransactionsSuccessBlock = successBlock; | ||
_restoreTransactionsFailureBlock = failureBlock; | ||
|
@@ -267,7 +267,7 @@ - (void)restoreTransactionsOfUser:(NSString*)userIdentifier | |
{ | ||
NSAssert([[SKPaymentQueue defaultQueue] respondsToSelector:@selector(restoreCompletedTransactionsWithApplicationUsername:)], @"restoreCompletedTransactionsWithApplicationUsername: not supported in this iOS version. Use restoreTransactionsOnSuccess:failure: instead."); | ||
_restoredCompletedTransactionsFinished = NO; | ||
_pendingRestoredTransactionsCount = 0; | ||
[_pendingRestoredTransactionIds removeAllObjects]; | ||
_restoreTransactionsSuccessBlock = successBlock; | ||
_restoreTransactionsFailureBlock = failureBlock; | ||
[[SKPaymentQueue defaultQueue] restoreCompletedTransactionsWithApplicationUsername:userIdentifier]; | ||
|
@@ -392,7 +392,7 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue | |
{ | ||
RMStoreLog(@"restore transactions finished"); | ||
_restoredCompletedTransactionsFinished = YES; | ||
|
||
[self notifyRestoreTransactionFinishedIfApplicableAfterTransaction:nil]; | ||
} | ||
|
||
|
@@ -478,7 +478,7 @@ - (void)didFinishDownload:(SKDownload*)download queue:(SKPaymentQueue*)queue | |
{ | ||
SKPaymentTransaction *transaction = download.transaction; | ||
RMStoreLog(@"download %@ for product %@ finished", download.contentIdentifier, transaction.payment.productIdentifier); | ||
|
||
[self postNotificationWithName:RMSKDownloadFinished download:download userInfoExtras:nil]; | ||
|
||
const BOOL hasPendingDownloads = [self.class hasPendingDownloadsInTransaction:transaction]; | ||
|
@@ -525,7 +525,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:^{ | ||
|
@@ -544,23 +544,23 @@ - (void)didPurchaseTransaction:(SKPaymentTransaction *)transaction queue:(SKPaym | |
- (void)didFailTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQueue*)queue error:(NSError*)error | ||
{ | ||
SKPayment *payment = transaction.payment; | ||
NSString* productIdentifier = payment.productIdentifier; | ||
NSString* productIdentifier = payment.productIdentifier; | ||
RMStoreLog(@"transaction failed with product %@ and error %@", productIdentifier, error.debugDescription); | ||
|
||
if (error.code != RMStoreErrorCodeUnableToCompleteVerification) | ||
{ // If we were unable to complete the verification we want StoreKit to keep reminding us of the transaction | ||
[queue finishTransaction:transaction]; | ||
} | ||
|
||
RMAddPaymentParameters *parameters = [self popAddPaymentParametersForIdentifier:productIdentifier]; | ||
if (parameters.failureBlock != nil) | ||
{ | ||
parameters.failureBlock(transaction, error); | ||
} | ||
|
||
NSDictionary *extras = error ? @{RMStoreNotificationStoreError : error} : nil; | ||
[self postNotificationWithName:RMSKPaymentTransactionFailed transaction:transaction userInfoExtras:extras]; | ||
|
||
if (transaction.transactionState == SKPaymentTransactionStateRestored) | ||
{ | ||
[self notifyRestoreTransactionFinishedIfApplicableAfterTransaction:transaction]; | ||
|
@@ -569,9 +569,12 @@ - (void)didFailTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQ | |
|
||
- (void)didRestoreTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQueue*)queue | ||
{ | ||
RMStoreLog(@"transaction restored with product %@", transaction.originalTransaction.payment.productIdentifier); | ||
|
||
_pendingRestoredTransactionsCount++; | ||
NSString *productIdentifier = transaction.originalTransaction.payment.productIdentifier; | ||
RMStoreLog(@"transaction restored with product %@", productIdentifier); | ||
|
||
if(productIdentifier) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: if (productIdentifier) |
||
[_pendingRestoredTransactionIds addObject:productIdentifier]; | ||
} | ||
if (self.receiptVerifier != nil) | ||
{ | ||
[self.receiptVerifier verifyTransaction:transaction success:^{ | ||
|
@@ -634,15 +637,15 @@ - (void)finishTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQu | |
NSString* productIdentifier = payment.productIdentifier; | ||
[queue finishTransaction:transaction]; | ||
[self.transactionPersistor persistTransaction:transaction]; | ||
|
||
RMAddPaymentParameters *wrapper = [self popAddPaymentParametersForIdentifier:productIdentifier]; | ||
if (wrapper.successBlock != nil) | ||
{ | ||
wrapper.successBlock(transaction); | ||
} | ||
|
||
[self postNotificationWithName:RMSKPaymentTransactionFinished transaction:transaction userInfoExtras:nil]; | ||
|
||
if (transaction.transactionState == SKPaymentTransactionStateRestored) | ||
{ | ||
[self notifyRestoreTransactionFinishedIfApplicableAfterTransaction:transaction]; | ||
|
@@ -654,9 +657,9 @@ - (void)notifyRestoreTransactionFinishedIfApplicableAfterTransaction:(SKPaymentT | |
if (transaction != nil) | ||
{ | ||
[_restoredTransactions addObject:transaction]; | ||
_pendingRestoredTransactionsCount--; | ||
[_pendingRestoredTransactionIds removeObject:transaction.payment.productIdentifier]; | ||
} | ||
if (_restoredCompletedTransactionsFinished && _pendingRestoredTransactionsCount == 0) | ||
if (_restoredCompletedTransactionsFinished && _pendingRestoredTransactionIds.count == 0) | ||
{ // Wait until all restored transations have been verified | ||
NSArray *restoredTransactions = [_restoredTransactions copy]; | ||
if (_restoreTransactionsSuccessBlock != nil) | ||
|
@@ -711,7 +714,7 @@ - (void)request:(SKRequest *)request didFailWithError:(NSError *)error | |
|
||
- (void)addProduct:(SKProduct*)product | ||
{ | ||
_products[product.productIdentifier] = product; | ||
_products[product.productIdentifier] = product; | ||
} | ||
|
||
- (void)postNotificationWithName:(NSString*)notificationName download:(SKDownload*)download userInfoExtras:(NSDictionary*)extras | ||
|
@@ -748,17 +751,17 @@ - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu | |
RMStoreLog(@"products request received response"); | ||
NSArray *products = [NSArray arrayWithArray:response.products]; | ||
NSArray *invalidProductIdentifiers = [NSArray arrayWithArray:response.invalidProductIdentifiers]; | ||
|
||
for (SKProduct *product in products) | ||
{ | ||
RMStoreLog(@"received product with id %@", product.productIdentifier); | ||
[self.store addProduct:product]; | ||
} | ||
|
||
[invalidProductIdentifiers enumerateObjectsUsingBlock:^(NSString *invalid, NSUInteger idx, BOOL *stop) { | ||
RMStoreLog(@"invalid product with id %@", invalid); | ||
}]; | ||
|
||
if (self.successBlock) | ||
{ | ||
self.successBlock(products, invalidProductIdentifiers); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refrain from making style changes. It makes the PR harder to review, and -unless done globally- makes the code style heterogenous.