Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)buyaudio
- {
- /* SKProductsRequest *request= [[SKProductsRequest alloc]
- initWithProductIdentifiers: [NSSet setWithObject: @"com.metatagg.3310identifier"]];
- request.delegate = self;
- [request start]; */
- NSLog(@"connect itune");
- }
- - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
- {
- [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
- NSArray *myProduct = response.products;
- NSLog(@"%@",[[myProduct objectAtIndex:0] productIdentifier]);
- //Since only one product, we do not need to choose from the array. Proceed directly to payment.
- SKPayment *newPayment = [SKPayment paymentWithProduct:[myProduct objectAtIndex:0]];
- [[SKPaymentQueue defaultQueue] addPayment:newPayment];
- }
- - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
- {
- for (SKPaymentTransaction *transaction in transactions)
- {
- switch (transaction.transactionState)
- {
- case SKPaymentTransactionStatePurchased:
- [self completeTransaction:transaction];
- break;
- case SKPaymentTransactionStateFailed:
- [self failedTransaction:transaction];
- break;
- case SKPaymentTransactionStateRestored:
- [self restoreTransaction:transaction];
- default:
- break;
- }
- }
- }
- - (void) restoreTransaction: (SKPaymentTransaction *)transaction
- {
- NSLog(@"Transaction Restored");
- [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
- }
- - (void) failedTransaction: (SKPaymentTransaction *)transaction
- {
- if (transaction.error.code != SKErrorPaymentCancelled)
- {
- // Display an error here.
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase Unsuccessful"
- message:@"Your purchase failed. Please try again."
- delegate:self
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [alert show];
- }
- // Finally, remove the transaction from the payment queue.
- [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
- }
Advertisement
Add Comment
Please, Sign In to add comment