title: How to do in-app purchase in ios5?
body: <p>I have used the following code for in-app purchase.</p>
  
  <pre><code>- (void)viewDidLoad {
  if ([SKPaymentQueue canMakePayments]) {
      NSLog(@"Can Buy Product");
  
      SKProductsRequest *productRequest=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@"com.mycompany.myproduct.productpack"]];
      productRequest.delegate=self;
      [productRequest start];
  }
  else {
  
      NSLog(@"Product Can't be purchased");
  }
  }
  
  -(IBAction)purchasePack1 {
  
  SKPayment *payment=[SKPayment paymentWithProductIdentifier:@"com.mycompany.myproduct.productpack"];
  [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
  [[SKPaymentQueue defaultQueue] addPayment:payment];
  
  }
  
  
  -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
  
  validProduct=nil;
  int count=[response.products count];
  if (count&gt;0) {
      NSLog(@"Product Avail");
  
      validProduct=[response.products objectAtIndex:0];
  }
  else {
      NSLog(@"No Product avail");
      [purchaseBtn setHidden:TRUE];
  }
  }
  
  
  -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
  
  for (SKPaymentTransaction *transaction in transactions) {
      switch (transaction.transactionState) {
          case SKPaymentTransactionStatePurchasing:
              NSLog(@"Purchasing");   
              [activityIndicatorObj setHidden:FALSE];
              [activityIndicatorObj startAnimating];
              break;
  
          case SKPaymentTransactionStatePurchased:
  
              UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"Congrats" message:@"Thanks For Purchasing " delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
              [alt show];
              [alt release];
              NSLog(@"Purchased");
              [activityIndicatorObj stopAnimating];
              [activityIndicatorObj setHidden:TRUE];
              [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
              break;
  
              case SKPaymentTransactionStateFailed:
  
              if (transaction.error.code!=SKErrorPaymentCancelled) {
  
                  NSLog(@"Cancelled");
  
              }
              [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
  
              UIAlertView *alt1=[[UIAlertView alloc]initWithTitle:@"Sorry" message:@"Some Error Encountered!" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
                  [alt1 show];
                  [alt1 release];
              NSLog(@"Failed");
              [activityIndicatorObj stopAnimating];
              [activityIndicatorObj setHidden:TRUE];
              break;
  
              case SKPaymentTransactionStateRestored:
              NSLog(@"Restored");
              [activityIndicatorObj stopAnimating];
              [activityIndicatorObj setHidden:TRUE];
              [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
              break;
  
  
  
          default:
              break;
      }
  }
  }
  </code></pre>
  
  <p>When i click purchase Button i am getting an alert message saying "You have already purchased this product and hasn't downloaded yet, Do you want to download.?"
  When i click yes i didn't get any response from App, and i am sure that product hasn't downloaded. Can anyone please tell me the suggestion for this problem. Thanks in Advance.</p>