SKProduct response is empty

Hi there! I think my store kit code is fine it may be the connection between itunes connect. The problem is during the reuqest, the did recieve response function runs, but no products are appended. I'm 18 and very new to this so any help would be appreciated, thanks! Here is my code:


import Foundation

import SpriteKit

import AVFoundation

import StoreKit

class SettingsScene : SKScene, SKProductsRequestDelegate, SKPaymentTransactionObserver {

var background1 = SKSpriteNode()

var AudioPlayer = AVAudioPlayer()

var removeAdsButton : UIButton!

var unlockLevelsButton : UIButton!

var list = [SKProduct]()

var p = SKProduct()

var lblAd: UILabel!

var lblCoinAmount: UILabel!

override func didMoveToView(view: SKView) {

if(SKPaymentQueue.canMakePayments()) {

print("IAP is enabled, loading")

let productID:NSSet = NSSet(objects: "com.seanfrost.supershooter.removeads", "com.seanfrost.supershooter.unlocklevels")

let request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)

request.delegate = self

request.start()

}

else {

print("please enable IAPS")

}

let removeAdsButtonImage = UIImage(named: "leftPurchaseButton")

removeAdsButton = UIButton(frame: CGRect(x: view.frame.size.width/2 - 105, y: view.frame.size.height/2 - 110, width:212, height: 62))

removeAdsButton.setTitleShadowColor(UIColor.blackColor(), forState: UIControlState.Highlighted)

removeAdsButton.setTitleShadowColor(UIColor.whiteColor(), forState: UIControlState.Normal)

removeAdsButton.setBackgroundImage(removeAdsButtonImage, forState: UIControlState.Normal)

removeAdsButton.setTitle("Remove Ads", forState: UIControlState.Normal)

removeAdsButton.titleLabel!.font = UIFont(name: "arial", size: 30)

removeAdsButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)

removeAdsButton.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center

removeAdsButton.addTarget(self, action: Selector("btnRemoveAds"), forControlEvents: UIControlEvents.TouchUpInside)

self.view?.addSubview(removeAdsButton)

let unlockLevelsButtonImage = UIImage(named: "leftPurchaseButton")

unlockLevelsButton = UIButton(frame: CGRect(x: view.frame.size.width/2 - 105, y: view.frame.size.height/2 + 110, width:212, height: 62))

unlockLevelsButton.setTitleShadowColor(UIColor.blackColor(), forState: UIControlState.Highlighted)

unlockLevelsButton.setTitleShadowColor(UIColor.whiteColor(), forState: UIControlState.Normal)

unlockLevelsButton.setBackgroundImage(unlockLevelsButtonImage, forState: UIControlState.Normal)

unlockLevelsButton.setTitle("Unlock Levels", forState: UIControlState.Normal)

unlockLevelsButton.titleLabel!.font = UIFont(name: "arial", size: 30)

unlockLevelsButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)

unlockLevelsButton.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center

unlockLevelsButton.addTarget(self, action: Selector("btnAddCoins"), forControlEvents: UIControlEvents.TouchUpInside)

self.view?.addSubview(unlockLevelsButton)

removeAdsButton.enabled = false

unlockLevelsButton.enabled = false

}

func btnRemoveAds() {

print("remove ads button pressed")

for product in list {

let prodID = product.productIdentifier

if(prodID == "com.seanfrost.supershooter.removeads") {

p = product

buyProduct()

break;

}

}

}

func btnAddCoins() {

for product in list {

let prodID = product.productIdentifier

if(prodID == "com.seanfrost.supershooter.unlocklevels") {

p = product

buyProduct()

break;

}

}

}

func removeAds() {

print("ads removed")

}

func addCoins() {

numberOfCoins = numberOfCoins + 50

print("coins added")

}

func RestorePurchases() {

SKPaymentQueue.defaultQueue().addTransactionObserver(self)

SKPaymentQueue.defaultQueue().restoreCompletedTransactions()

}

func buyProduct() {

print("buy " + p.productIdentifier)

let pay = SKPayment(product: p)

SKPaymentQueue.defaultQueue().addTransactionObserver(self)

SKPaymentQueue.defaultQueue().addPayment(pay as SKPayment)

}

func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {

print("product request")

let myProduct = response.products

for product in myProduct {

print("product added")

print(product.productIdentifier)

print(product.localizedTitle)

print(product.localizedDescription)

print(product.price)

list.append(product)

}

removeAdsButton.enabled = true

unlockLevelsButton.enabled = true

}

func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue) {

print("transactions restored")

for transaction in queue.transactions {

let t: SKPaymentTransaction = transaction

let prodID = t.payment.productIdentifier as String

switch prodID {

case "com.seanfrost.supershooter.removeads":

print("remove ads")

removeAds()

case "com.seanfrost.supershooter.unlocklevels":

print("add coins to account")

addCoins()

default:

print("IAP not setup")

}

}

}

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("buy, ok unlock iap here")

print(p.productIdentifier)

let prodID = p.productIdentifier as String

switch prodID {

case "com.seanfrost.supershooter.removeads":

print("remove ads")

removeAds()

case "com.seanfrost.supershooter.unlocklevels":

print("add coins to account")

addCoins()

default:

print("IAP not setup")

}

queue.finishTransaction(trans)

break;

case .Failed:

print("buy error")

queue.finishTransaction(trans)

break;

default:

print("default")

break;

}

}

}

func finishTransaction(trans:SKPaymentTransaction)

{

print("finish trans")

SKPaymentQueue.defaultQueue().finishTransaction(trans)

}

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

{

print("remove trans");

}

}

Replies

So you wrote this:


"the did recieve response function runs, but no products are appended."


Did you mean "the didReceiveResponse method was called but the response.products array was empty"?


If so there are many reasons why you might get no valid products. Search this forum, the "In App Purchaee Resources" post on the side of this forum and also:

https://developer.apple.com/library/ios/technotes/tn2413/_index.html

Folks, you should never ask your questions like this. Nobody will read through your code trying to find out how it supposed to work. Try to localize the error.