Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You shouldn't release <code>SKProductsRequest *request</code> right after you start the request, but should have released it in both delegate methods. Check <a href="http://developer.apple.com/library/ios/#documentation/StoreKit/Reference/SKRequestDelegate/Reference/Reference.html" rel="nofollow">the documentation</a> for parent <code>SKRequest</code> class which says:</p> <blockquote> <p>When this method (<code>requestDidFinish</code> or <code>request:didFailWithError:</code>) is called, your delegate receives no further communication from the request and can release it.</p> </blockquote> <p>I don't know why this worked for you in newer versions of SDK, but strictly looking at your code, request could potentially be released before the response could have invoked the delegate methods.</p> <p>This is how I would do it:</p> <pre><code>- (void)requestPurchaseOfCompetition:(Competition*)competition { DLog(""); if ([SKPaymentQueue canMakePayments]) { DLog(@"do store"); NSString* productIdentifier = [NSString stringWithFormat:@"%@%@_%@", kPRODUCT_IDENTIFIER_PREFIX, competition.competitionId, competition.season]; SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:productIdentifier]]; [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationRequestProductInfo object:nil userInfo:[NSDictionary dictionaryWithObject:request forKey:@"request"]]]; request.delegate = self; [request start]; } else { DLog(@"no store"); // Warn the user that purchases are disabled. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Store", @"Store") message:NSLocalizedString(@"In app purchasing is disabled for this device (in Settings &gt; General &gt; Restrictions). Please enable this setting to purchase more competitions.", @"In app purchasing is disabled for this device (in Settings &gt; General &gt; Restrictions). Please enable this setting to purchase more competitions.") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release]; } } ... - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { DLog(@"response: %@", response); DLog(@"invalid product identifiers: %@", response.invalidProductIdentifiers); for (SKProduct *product in response.products) { DLog(@"product: %@", product); [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationGotProductInfo object:nil userInfo:[NSDictionary dictionaryWithObject:product forKey:@"product"]]]; SKPayment *payment = [SKPayment paymentWithProduct:product]; SKPaymentQueue *paymentQueue = [SKPaymentQueue defaultQueue]; [paymentQueue addTransactionObserver:self]; [paymentQueue addPayment:payment]; } [request release]; } - (void)request:(SKRequest *)request didFailWithError:(NSError *)error { DLog(@"request failed: %@, %@", request, error); [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationRequestProductInfoFailed object:nil userInfo:[NSDictionary dictionaryWithObject:error forKey:@"error"]]]; [request release]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload