Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use this code, it might help you....</p> <pre><code> //To Show Alert of InAppPurchase - (void)showAlert { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Click buy to purchase full tracks and other functionalities of the application." delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil]; [alert addButtonWithTitle:@"Buy"]; [alert addButtonWithTitle:@"Restore Transaction"]; [alert addButtonWithTitle:@"Cancel"]; [alert show]; } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex{ if(buttonIndex==0) { // For buy an item [self Declarations]; } else if(buttonIndex == 1) { //For Restore Previous Transaction [self restorePreviousTransaction:nil]; } else { //Do something here.. } } #pragma mark In App Purchase -(void)Declarations { if ([SKPaymentQueue canMakePayments]) { NSLog(@"parental functions are disabled"); SKProductsRequest *productRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObjects:@"com.tapmobi.careerandsuccess.inapp",nil]]; productRequest.delegate=self; [productRequest start]; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; } else { NSLog(@"parental functions are enabled"); } } - (IBAction)restorePreviousTransaction:(id)sender { [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; } -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse: (SKProductsResponse *)response { SKProduct *validProduct=nil; int count = [response.products count]; NSLog(@"number of prouducts present:%d",count); if(count==0){ [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; return; } validProduct = [response.products objectAtIndex:0]; NSLog(@"the product is :%@",validProduct.localizedTitle); SKPayment *skpayment = [SKPayment paymentWithProduct:validProduct]; [[SKPaymentQueue defaultQueue] addPayment:skpayment]; [[SKPaymentQueue defaultQueue]addTransactionObserver:self]; } -(void)requestDidFinish:(SKRequest *)request { [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; } -(void)request:(SKRequest *)request didFailWithError:(NSError *)error { [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; NSLog(@"Failed to connect with error: %@", [error localizedDescription]); } -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; NSString *message = [[NSString alloc]init]; BOOL bSuccess = NO; for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStatePurchasing: NSLog(@"stuff is getting purchased"); break; case SKPaymentTransactionStatePurchased: NSLog(@"purchased properly"); message = @"Thank you."; [[NSUserDefaults standardUserDefaults] setValue:@"Full Version" forKey:PURCHASED_KEY]; [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; bSuccess = YES; break; case SKPaymentTransactionStateRestored: [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; break; case SKPaymentTransactionStateFailed: if (transaction.error.code != SKErrorPaymentCancelled) { NSLog(@"error happened"); message = @"Purchase is not successfull. Try again later"; } [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; break; default: break; } } if (bSuccess){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:message delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; [alert show]; } } </code></pre> <p>Happy Coding..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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