2016-09-27 4 views
0

restorePurchases()を呼び出すと、非消耗com.premiumが復元されます。 IAPの購入の復元とIAPの購入を担当する機能は次のとおりです。これは、非消耗型IAPの問題に過ぎません。 購入に問題はありません。ユーザーがすでに持っているIAPを購入しようとすると、単に復元されます。これを見ていただきありがとうございます。IAPはまだ購入されていないときに復元されます

func restorePurchases() { 
    SKPaymentQueue.default().add(self) 
    SKPaymentQueue.default().restoreCompletedTransactions() 
} 

func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) { 
    print("transactions restored") 

    for transaction in queue.transactions { 
     let t: SKPaymentTransaction = transaction 

     let prodID = t.payment.productIdentifier as String 
     print("starting restoring") 
     switch prodID { 
     case "com.premium": 
      print("restoring ads") 
      removeAds() 
     case "com.cash": 
      print("we dont restore coins") 
     case "com.level": 
      print("we dont restore levels") 
     default: 
      print("can't restore") 
     } 
    } 

こちらも私の支払い待ちです。

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { 
    print("add paymnet") 

    for transaction:AnyObject in transactions { 
     let trans = transaction as! SKPaymentTransaction 
     print(trans.error) 

     switch trans.transactionState { 

     case .purchased: 
      print("buying, ok unlock iap here") 
      print(p.productIdentifier) 

      let prodID = p.productIdentifier as String 
      switch prodID { 
      case "com.premium": 
       print("buying ads") 
       removeAds() 
      case "com.cash": 
       print("buying coins") 
       addCoins() 
      case "com.level": 
       print("buying levels") 
       addLevels() 
      default: 
       print("can't buy") 
      } 

      queue.finishTransaction(trans) 
      break; 
     case .failed: 
      print("buy error") 
      queue.finishTransaction(trans) 
      break; 
     default: 
      print("default") 
      break; 

     } 
    } 
} 
+0

毎回新しいテストユーザーアカウントでテストしていますか? – brandonscript

+0

@brandonscriptはい私は毎回新しいアカウントを使いました。 – james

+0

「問題」であった元のコードが削除され、その回答が無効になったため、編集をロールバックしました。 – Paulw11

答えて

4

paymentQueueRestoreCompletedTransactionsFinishedの購入ステータスは更新しないでください。この機能は、復元処理が完了したことを通知するだけです。これを使用してUIを更新したり、アラートなどを表示することができます。

.restoredの状態を処理するupdatedTransactionsの状態に復元するトランザクションは、.purchasedの状態を処理するのと同じ方法で復元されます。

本質的に「復元」は、消耗品ではなく自動更新購読購入タイプの購入取引プロセスを再生するだけです。

+0

が好きな場合は、あなたの質問を編集して "新しい"コードを追加することができます。そのため、私のpaymentQueue関数の中で、スイッチのtrans.transactionStateにあります。私は修復されたケースを使うべきですか? – james

+0

はい、それは正しい – Paulw11

+0

私はrestorePurchases()を呼び出すと、.restoringAttemptに到達しますが、プリント(p.productIdentifier)はコンソールに空白行を表示し、デフォルトと状態になります:購入できません。ただし、購入ボタンを押してサインインしても購入しないでください。その後、私はそれを復元しようとします。最初にサインインするように促すには、restorePurchases()に何を含める必要がありますか?再度、感謝します。 – james

関連する問題