In App Purchases with multiple products

911 Views Asked by At

I am setting up a subscription app, and I want to have 2 options: 2 months, and 1 year. Here is the code I'm currently using that works for the 2 month purchase. How do I modify it to have both?

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()
    }
}

The problem occurs with the second function : getProductInfo(). How do I add a second product ID? I tried the following:

        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

There are 1 best solutions below

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

this works, but when you call it back from Apple it will alphabetize them. So make sure you test each array Index in the return function.