Skip to content

Commit

Permalink
Merge pull request #569 from ParsePlatform/nlutsenko.iap
Browse files Browse the repository at this point in the history
Safeguard API usage and delegate reset in ProductsRequestHandler.
  • Loading branch information
nlutsenko committed Nov 16, 2015
2 parents 7eb17b6 + 5ce2271 commit 3b5bd2e
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ - (instancetype)initWithProductsRequest:(SKProductsRequest *)request {
self = [super init];
if (!self) return nil;

_taskCompletionSource = [BFTaskCompletionSource taskCompletionSource];

_productsRequest = request;
_productsRequest.delegate = self;

Expand All @@ -63,8 +65,9 @@ - (void)dealloc {
///--------------------------------------

- (BFTask *)findProductsAsync {
_taskCompletionSource = [BFTaskCompletionSource taskCompletionSource];
[_productsRequest start];
if (!_taskCompletionSource.task.completed) {
[_productsRequest start];
}
return _taskCompletionSource.task;
}

Expand All @@ -73,20 +76,22 @@ - (BFTask *)findProductsAsync {
///--------------------------------------

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
_productsRequest.delegate = nil;

PFProductsRequestResult *result = [[PFProductsRequestResult alloc] initWithProductsResponse:response];
[self.taskCompletionSource trySetResult:result];
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
[self.taskCompletionSource trySetError:error];

// according to documentation, this method does not call requestDidFinish
request.delegate = nil;
_productsRequest.delegate = nil;

[self.taskCompletionSource trySetError:error];
}

- (void)requestDidFinish:(SKRequest *)request {
// the documentation assures that this is the point safe to get rid of the request
request.delegate = nil;
_productsRequest.delegate = nil;
}

@end

0 comments on commit 3b5bd2e

Please sign in to comment.