Skip to content

Commit

Permalink
Retain products requests on tvOS
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiou87 committed Apr 19, 2016
1 parent e0e7389 commit 08ea336
Showing 1 changed file with 13 additions and 3 deletions.
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

0 comments on commit 08ea336

Please sign in to comment.