2012-09-20 35 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