ios 沙盒恢复了非消耗性 IAP,无需购买

ios sandbox restored non-consumable IAP without buying

朋友们,关于在沙盒中测试 IAP 的问题。

我的步骤:

  1. 在 iTunes 中注册-连接新的沙盒测试器。
  2. itunes/appstore 上测试phone登出

  3. 从设备中删除应用程序

  4. 运行 在 Xcode.

在我的 phone 上展示得很漂亮。一切都按照我想要的方式工作。除了一种情况。

我只是不知道,也许它应该在 Sandbox,Sandbox-testers feauture 中。

在我实现了非消耗性 IAP 的视图控制器中,有两个按钮:"buy" 和 "restore."

点击"restore"(仅"restore"),然后输入刚刚注册的测试员的id/密码,我希望不会恢复任何东西,因为这个id从来没有被按下过"Buy"按钮。

但是恢复成功了。无需购买过程。 可以吗?

My code

import UIKit
import StoreKit

class PurchaseUI: UIViewController, SKProductsRequestDelegate, SKPaymentTransactionObserver{

override func viewDidLoad() {

    super.viewDidLoad()
    self.navigationItem.setHidesBackButton(true, animated:true)
    if (SKPaymentQueue.canMakePayments()) {
            let productID: NSSet = NSSet(object: "bla.bla.bla.pro1")
            let request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
            request.delegate = self
            request.start()
    }
}

@IBAction func buyBtn(sender: AnyObject) {
    for product in flag0{
        let prodID = product.productIdentifier
        if (prodID == ""bla.bla.bla.pro1""){
            flag1 = product
            buyproduct()
            break
        }
    }
}

func fullVers(){
    cashflag = true // global var
}

@IBAction func restorebtn(sender: AnyObject) {
    SKPaymentQueue.defaultQueue().addTransactionObserver(self)
    SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}

var flag0 = [SKProduct]()
var flag1 = SKProduct()

func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
    let myProduct = response.products
    for product in myProduct {
        flag0.append(product)
    }
}

func buyproduct(){
    let pay = SKPayment(product: flag1)
    SKPaymentQueue.defaultQueue().addTransactionObserver(self)
    SKPaymentQueue.defaultQueue().addPayment(pay as SKPayment)
}

func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue) {
    for transaction in queue.transactions {
        let t: SKPaymentTransaction = transaction as SKPaymentTransaction
        let prodID = t.payment.productIdentifier as String
        switch prodID {
        case "bla.bla.bla.pro1":
            fullVers()
        default:
            break
        }
    }
}

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction:AnyObject in transactions {
        let trans = transaction as! SKPaymentTransaction
        switch trans.transactionState {
        case .Purchased, .Restored:
            for transaction in queue.transactions {
                let t: SKPaymentTransaction = transaction as SKPaymentTransaction
                let prodID = t.payment.productIdentifier as String
                switch prodID {
                case "bla.bla.bla.pro1":
                    fullVers()
                default:
                    break
                }
            }
            queue.finishTransaction(trans)
            break
        case .Deferred:
            queue.finishTransaction(trans)
            break
        case .Failed:
            queue.finishTransaction(trans)
            break
        default:
            break
        }
    }
}

func finishTransaction(trans: SKPaymentTransaction){

}

func paymentQueue(queue: SKPaymentQueue, removedTransactions transactions: [SKPaymentTransaction]) {
}

}

在 paymentQueueRestoreCompletedTransactionsFinished 方法中,您需要检查交易状态 - 无论交易中发生什么,您都授予完全访问权限。该方法返回说交易已完成,但由于没有进行任何购买,因此应该不会发生任何事情。检查那里的 SKPaymentTransactionStateRestored,我认为应该可以解决问题。

您正在 paymentQueue:updatedTransactions 办理登机手续,但不是那个。