title: Problems with iPhone SDK StoreKit
body: <p>In my iPhone app Im using StoreKit to make it possible for users to buy subscriptions in the app. The problem I'm having is that suddenly everytime I start the app SKPaymentTransactionStatePurchased is sent to the observer so the app tries to buy the subscription again and again. And if I try to buy the subscription again from the list of subscriptions in the app I get a message saying "You've already purchased this In App Purchase but it hasn't been downloaded." then failedTransaction is called with SKErrorPaymentCancelled. </p>
  
  <p>EDIT: I have now found a lot of threads about this in the Apple Developer Forum, for example: <a href="https://devforums.apple.com/thread/73818" rel="nofollow">https://devforums.apple.com/thread/73818</a> and /thread/73572, it seems like a lot of developers have the same problem..</p>
  
  <p>This is the code I'm using, can you see something wrong with it?</p>
  
  <pre><code>-(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) failedTransaction: (SKPaymentTransaction *)transaction
  {
      if (transaction.error.code != SKErrorPaymentCancelled)
      {
          NSLog(@"Error"); 
      } else {
          NSLog(@"Cancel");
      }
      [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
  }
  
  -(void) restoreTransaction: (SKPaymentTransaction *)transaction
  {
      [self subscribe:transaction];
  }
  
  -(void) completeTransaction: (SKPaymentTransaction *)transaction
  {
      [self subscribe:transaction];
  }
  
  -(void)subscribe: (SKPaymentTransaction*)transaction { 
      NSInteger errorCode = //Connects to my server that verifies receipt with Apple server etc..
      if (errorCode==0) {
          [self provideContent];
      }
      [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
  }
  </code></pre>