Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

troop231

macrumors 603
Original poster
Jan 20, 2010
5,826
561
I'm trying to implement/build a timeout that gets fired at 15 seconds if the in app purchase can't be completed by iTunes. This also needs to work for restoring purchases. Can anyone help point me in the right direction?

Appreciate any help provided! Some code I've been working on:

Code:
- (IBAction)buyButtonTapped:(id)sender
{
    UIButton *buyButton = (UIButton *)sender;
    SKProduct *product = self.products[buyButton.tag];
    
    self.buyTimeoutTimer = [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(stopBuying) userInfo:nil repeats:NO];
    
    SKPayment *payment = [SKPayment paymentWithProduct:product];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (void)completeTransaction:(SKPaymentTransaction *)transaction
{
    // Here I invalidate the timer in case the purchase was completed before our 15 second timer gets fired
    [self.buyTimeoutTimer invalidate];
    [self provideContentForProductIdentifier:transaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)stopBuying
{
    // This is where I need to cancel the purchase (or) restore requests.
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.