2016-05-09 1 views
1

私のアプリでIn App購入と復元の購入方法を実装しました。以前に購入したIn App製品がない場合にアラートを表示

以前に購入したIn App製品がない場合は、単に警告メッセージを表示するだけです。

以下の現在の例では、支払い方法は復元要求の直後に初期化されます。 if queue.transactions.count == 0を参照するにはpaymentQueueRestoreCompletedTransactionsFinishedチェックで

// Buy Button that initiates In App purchase request 
-(IBAction)buyButtonPressed:(id)sender { 
    if (self.products != nil) 
    { 
     SKPayment *payment = [SKPayment paymentWithProduct:self.products]; 
     [[SKPaymentQueue defaultQueue]addTransactionObserver:self]; 
     [[SKPaymentQueue defaultQueue]addPayment:payment]; 
     [self.activityIndicator startAnimating]; 
    } 
} 

//Restore Button initiates In App Restore 
- (IBAction)restoreButtonPressed:(id)sender { 
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; 
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; 
} 

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue 
{ 
//Currently I’m displaying an alert here if there are no previous purchased products available. 
    if(queue.transactions.count == 0) 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"There is no restore available for your account" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
     [alert show]; 
     [self.activityIndicator stopAnimating]; 
     return; 
    } 

    NSMutableArray *purchasedItemIDs = [[NSMutableArray alloc] init]; 

     for (SKPaymentTransaction *transaction in queue.transactions) 
     { 
      NSString *productID = transaction.payment.productIdentifier; 
      [purchasedItemIDs addObject:productID]; 
       if ([productID isEqualToString:@"com.mydomain.app.product”]) 
       { 
       //Unlocks the App 
       [self unlockApp]; 
       [self.activityIndicator stopAnimating]; 
       } 
      } 

purchasedItemIDs = nil; 
} 

//Payment QUEUE 
-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { 
    for (SKPaymentTransaction *transaction in transactions) { 
     switch (transaction.transactionState) { 
     case SKPaymentTransactionStatePurchasing: 
      { 
      [self.activityIndicator startAnimating]; 
      break; 
      } 
     case SKPaymentTransactionStatePurchased: 
      { 
      [self unlockApp]; 
      [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 
      [self.activityIndicator stopAnimating]; 
      break; 
      } 
     case SKPaymentTransactionStateRestored: 
      { 
      [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 
      [self unlockApp]; 
      [self showAlert:@"Application successfully restored"]; 
      [self.activityIndicator stopAnimating]; 
      break; 
      } 
    case SKPaymentTransactionStateFailed: 
    { 
     [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 
     [self.activityIndicator stopAnimating]; 
     break;   
    } 
    case SKPaymentTransactionStateDeferred: 
      { 
      [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 
      [self.activityIndicator stopAnimating]; 
      break; 
      } 
      default: 
      [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 
      [self.activityIndicator stopAnimating]; 
      break; 
     } 
    } 
} 
+0

あなたは、これまで何を試してみましたか? [最小限で完全で検証可能な例を作成する方法](http://stackoverflow.com/help/mcve)リンクと[how to ask](http://stackoverflow.com/help/asking)リンクを確認し、 stackoverflowがどのように機能するかを知る。 –

答えて

0

。そうであれば、復元する購入はありません。たとえば、次のように

-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue { 
    // Check to see if there are purchases to restore 
    if (queue.transactions.count == 0) { 
     // No purchases to restore 
     // Show alert 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Purchases" 
                 message:@"There are no purchases to restore." 
                 delegate:self 
               cancelButtonTitle:@"Close" 
               otherButtonTitles:nil]; 
     [alert show]; 
    } 
    else { 
     // There are purchases to restore 
     // Do something else 
    } 
} 

SKPaymentTransactionObserver Protocol Reference

+0

私は詳細について私の質問を説明してくれて、親切にも私の質問を再考し、私が何をしたいのかを教えてください。ありがとう –

+0

@AmmarSaeed私は質問がどのように変わったのか分かりません。あなたはまだ同じ質問をしています。 –

+0

私はあなたが提案したものを既に実装していますが、アプリ内購入を復元する場合にituneがサインインされている場合は、ユーザーの資格情報を再度取得せずに事前警告が必要です。 –

関連する問題