There is a problem with the implementation of LAInAppHelper in the manual that you linked : the helper considers your application as non-competitive.
Here's what happens: a shared instance of LAInAppHelper has a sharedInstance to which _completionHandler belongs (by the way).
The requestProductsWithCompletionHandler: method assigns _completionHandler copy of the passed block. This is normal for the first request, but if another request is "in flight", the completion block of this other request will be issued by ARC due to this reassignment. If the tab you are switching to launches a parallel request, the initial request returns to the issued block, causing undefined behavior and possibly fail.
To fix this problem, you need to split the class into two parts containing elements common to all requests (namely _productIdentifiers and _purchasedProductIdentifiers ) and specific to the request ( _productsRequest and _completionHandler ).
The first class instance (let it be called LAInAppHelper ) remains common; instances of the second class (let it be called LAInAppHelperRequest ) are created by request inside the requestProductsWithCompletionHandler: method.
-(id)initWithHelper:(LAInAppHelper*)helper andCompletionHandler:(RequestProductsCompletionHandler)completionHandler { if (self = [super init]) { _completionHandler = [completionHandler copy]; _productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:helper.productIdentifiers];
You will need to create a block that also wraps _completionHandler as follows:
- (void)requestProductsWithCompletionHandler:(RequestProductsCompletionHandler)completionHandler { __block LAInAppHelperRequest *req = [[LAInAppHelperRequest alloc] initWithHelper:self andCompletionHandler:^(BOOL success, NSArray *products) { completionHandler(success, products); req = nil; }]; }
source share