2012-09-20 34 views
2

我尝试了几个解决方案,但从未成功。我想要的是当用户点击Buy Button时,UIAlertViewUIActivityIndicatorView出现等待应用程序访问应用程序商店。但是一旦购买完成,我不知道该去哪里消除这个UIAlertView。我知道,驳回UIAlertView,我们使用:[alert dismissWithClickedButtonIndex:-1 animated:YES];iOS:在应用程序购买与购买进度指示器UIActivityIndi​​catorView

所以,请你帮我回答两个问题:

1)是我的代码如下OK或任何其他更好的实现呢?

2)我应该在哪里解雇UIAlertView的所有情况:

  • 用户接受购买
  • 用户取消购买
  • 购买不成功

以下是我的代码:

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{ 
    UIAlertView *alert; 
    for(SKPaymentTransaction *transaction in transactions){ 
     switch (transaction.transactionState) { 
      case SKPaymentTransactionStatePurchasing:     
       alert = [[UIAlertView alloc]initWithTitle: @"In App Purchase" message: @"Processing your purchase..." delegate: nil cancelButtonTitle: nil otherButtonTitles: nil]; 
       UIActivityIndicatorView *ind = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge]; 
       [ind startAnimating];  
       [alert addSubview: ind]; 
       [alert show]; 
       [ind release]; 
       [alert release]; 
       break; 
      case SKPaymentTransactionStatePurchased: 
       [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 
       UIAlertView *tmp = [[UIAlertView alloc] 
            initWithTitle:@"Complete" 
            message:@"You have bought the full version!" 
            delegate:self 
            cancelButtonTitle:nil 
            otherButtonTitles:@"Ok", nil]; 
       [tmp show]; 
       [tmp release]; 
       break; 
      case SKPaymentTransactionStateRestored: 
       [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 
       break; 
      case SKPaymentTransactionStateFailed: 
       if (transaction.error.code !=SKErrorPaymentCancelled) { 
        [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 
        UIAlertView *tmp = [[UIAlertView alloc] 
             initWithTitle:@"Error" 
             message:@"Purchase not successful!" 
             delegate:self 
             cancelButtonTitle:nil 
             otherButtonTitles:@"Ok", nil]; 
        [tmp show]; 
        [tmp release];    
       } 
       [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 
       break; 
     } 
    } 
} 

回答

0

尝试添加

case SKPaymentTransactionStatePurchased: 
[alert dismissWithClickedButtonIndex:-1 animated:YES]; 

case SKPaymentTransactionStateFailed: 
[alert dismissWithClickedButtonIndex:-1 animated:YES]; 
+0

我做了,但是当你按下'购买Button'第二次,'UIAlertView'还有永远 – DavidNg

+0

秒时间?之后你会看到一个“完整”的消息? – CReaTuS

+0

我点击'购买按钮',然后点击'取消',然后再次点击'购买按钮',警报显示为永久 – DavidNg