Skip to content
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

Retain products requests (necessary for tvOS) #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions RMStore/RMStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ @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;
NSMutableSet *_productsRequests;

NSMutableArray *_restoredTransactions;

Expand All @@ -154,6 +155,7 @@ - (id) init
_addPaymentParameters = [NSMutableDictionary dictionary];
_products = [NSMutableDictionary dictionary];
_productsRequestDelegates = [NSMutableSet set];
_productsRequests = [NSMutableSet set];
_restoredTransactions = [NSMutableArray array];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
Expand Down Expand Up @@ -241,7 +243,8 @@ - (void)requestProducts:(NSSet*)identifiers

SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:identifiers];
productsRequest.delegate = delegate;

[_productsRequests addObject:productsRequest];

[productsRequest start];
}

Expand Down Expand Up @@ -739,6 +742,11 @@ - (void)removeProductsRequestDelegate:(RMProductsRequestDelegate*)delegate
[_productsRequestDelegates removeObject:delegate];
}

- (void)removeProductsRequest:(SKProductsRequest*)productsRequest
{
[_productsRequests removeObject:productsRequest];
}

@end

@implementation RMProductsRequestDelegate
Expand Down Expand Up @@ -767,12 +775,13 @@ - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu
[[NSNotificationCenter defaultCenter] postNotificationName:RMSKProductsRequestFinished object:self.store userInfo:userInfo];
}

- (void)requestDidFinish:(SKRequest *)request
- (void)requestDidFinish:(SKProductsRequest *)request
{
[self.store removeProductsRequestDelegate:self];
[self.store removeProductsRequest:request];
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error
- (void)request:(SKProductsRequest *)request didFailWithError:(NSError *)error
{
RMStoreLog(@"products request failed with error %@", error.debugDescription);
if (self.failureBlock)
Expand All @@ -786,6 +795,7 @@ - (void)request:(SKRequest *)request didFailWithError:(NSError *)error
}
[[NSNotificationCenter defaultCenter] postNotificationName:RMSKProductsRequestFailed object:self.store userInfo:userInfo];
[self.store removeProductsRequestDelegate:self];
[self.store removeProductsRequest:request];
}

@end