Making the Purchase

Now that we know how the button state is managed, let's look at how clicking one of the purchase buttons triggers a purchase. Listing 10–7 shows the code that is run when a user presses the saucer button.

Listing 10–7. ExtrasController.m (saucerButtonClicked:)

- (IBAction)saucerButtonClicked:(id)sender {     if ([gameParams.purchases containsObject:PURCHASE_INGAME_SAUCERS]){         [gameParams setIncludeSaucers:![gameParams includeSaucers]];         [self setGameParams:gameParams];         [gameParams writeToDefaults];     } else {         SKPayment* payRequest = [SKPayment paymentWithProductIdentifier: PURCHASE_INGAME_SAUCERS];         [[SKPaymentQueue defaultQueue] addPayment:payRequest];     } }

In Listing 10–7, we see ...

Get Beginning iOS 5 Games Development: Using the iOS 5 SDK for iPad, iPhone, and iPod Touch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.