在App中购买多个产品

时间:2015-06-12 18:08:59

标签: swift in-app-purchase itunesconnect

我正在设置订阅应用,我希望有2个选项:2个月和1年。这是我目前使用的代码,适用于2个月的购买。如何修改它以同时拥有它们?

func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {
    let products = response.products
    if products.count != 0 {
        product = products[0] as! SKProduct
    }
}



func getProductInfo() {
        if SKPaymentQueue.canMakePayments() {
            let productID : NSSet = NSSet(object: "2MonthPrem")
            let request : SKProductsRequest = SKProductsRequest(productIdentifiers: productID as Set<NSObject>)
            request.delegate = self
            request.start()
    }
}

第二个函数出现问题:getProductInfo()。如何添加第二个产品ID?我尝试了以下方法:

        if SKPaymentQueue.canMakePayments() {
            let productID : NSSet = NSSet(object: "2MonthPrem")
            let productIDTwo : NSSet = NSSet(object: "1YearPrem")
            let request : SKProductsRequest = SKProductsRequest(productIdentifiers: [productID, productIDTwo] as Set<NSObject>)
            request.delegate = self
            request.start()
    }

1 个答案:

答案 0 :(得分:0)

let productID : NSSet = NSSet(array: ["2MonthPrem", "1YearPrem"])

这样可行,但是当你从Apple调用它时,它会按字母顺序排列它们。因此,请确保在返回函数中测试每个数组索引。