ios sandbox在没有购买的情况下恢复了非消耗性IAP

时间:2015-11-12 18:22:55

标签: swift in-app-purchase xcode7 sandbox

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

我的步骤:

  1. 注册itunes - 连接新的沙盒测试仪。
  2. 测试手机上的itunes / appstore注销

  3. 从设备删除应用

  4. 在Xcode中运行。

  5. 我手机上的所有内容都很漂亮。一切都按照我想要的方式运作。除了一种情况。

    我只是不知道,也许它应该出现在Sandbox-Sandters测试人员的沙盒中。

    在我的视图控制器中,实现了非消耗性IAP,有两个按钮:"购买"和"恢复。"

    点击"恢复" (只有"恢复"),输入id /密码只是注册的测试人员,我希望没有任何东西可以恢复,因为这个id从未被按下"购买"按钮。

    但复苏是成功的。没有购买流程。 没关系?

      

    我的代码

    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]) {
    }
    

    }

1 个答案:

答案 0 :(得分:0)

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

您正在检查paymentQueue:updatedTransactions但不在那个。