productos Solicitud no funciona rápido para compras en la aplicación

Escribí un código para get mi compra en la aplicación para eliminar mis anuncios. La respuesta vuelve a aparecer en blanco y vuelve con un error porque es nil aquí está mi código completo para la compra en la aplicación:

override func viewDidLoad() { super.viewDidLoad() outRemoveAds.enabled = false if(SKPaymentQueue.canMakePayments()) { println("IAP is enabled, loading") var productID:NSSet = NSSet(objects: "com.webstart.tomsgamesinc.StartLight_No_Ads") var request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as Set<NSObject>) request.delegate = self request.start() } else { println("please enable IAPS") } // Do any additional setup after loading the view. } func buyProduct() { println("buy " + p.productIdentifier) var pay = SKPayment(product: p) SKPaymentQueue.defaultQueue().addTransactionObserver(self) SKPaymentQueue.defaultQueue().addPayment(pay as SKPayment) } //3 func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) { println("product request") println(response.products) var myProduct = response.products for product in myProduct { println("product added") println(product.productIdentifier) println(product.localizedTitle) println(product.localizedDescription) println(product.price) list.append(product as! SKProduct) } outRemoveAds.enabled = true } // 4 func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) { println("transactions restnetworking") var purchasedItemIDS = [] for transaction in queue.transactions { var t: SKPaymentTransaction = transaction as! SKPaymentTransaction let prodID = t.payment.productIdentifier as String switch prodID { case "com.webstart.tomsgamesinc.StartLight_No_Ads": println("remove ads") removeAds() default: println("IAP not setup") } } } // 5 func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) { println("add paymnet") for transaction:AnyObject in transactions { var trans = transaction as! SKPaymentTransaction println(trans.error) switch trans.transactionState { case .Purchased: println("buy, ok unlock iap here") println(p.productIdentifier) let prodID = p.productIdentifier as String switch prodID { case "com.webstart.tomsgamesinc.StartLight_No_Ads": println("remove ads") removeAds() println("add coins to account") default: println("IAP not setup") } queue.finishTransaction(trans) break; case .Failed: println("buy error") queue.finishTransaction(trans) break; default: println("default") break; } } } // 6 func finishTransaction(trans:SKPaymentTransaction) { println("finish trans") SKPaymentQueue.defaultQueue().finishTransaction(trans) } //7 func paymentQueue(queue: SKPaymentQueue!, removedTransactions transactions: [AnyObject]!) { println("remove trans"); } @IBAction func btnRemoveAds(sender: UIButton) { for product in list { println("ProdID") var prodID = product.productIdentifier println(prodID) if(prodID == "com.webstart.tomsgamesinc.StartLight_No_Ads") { p = product buyProduct() break; } } } 

Agregué la compra en iTunes connect.

He actualizado su código de esta manera:

 import UIKit import StoreKit class ViewController: UIViewController, SKProductsRequestDelegate, SKPaymentTransactionObserver { var productID = "com.webstart.tomsgamesinc.StartLight_No_Ads" var product: SKProduct? var isProductRecive = false override func viewDidLoad() { super.viewDidLoad() getProductInfo() SKPaymentQueue.defaultQueue().addTransactionObserver(self) } @IBAction func btnRemoveAds(sender: UIButton) { if isProductRecive{ let payment = SKPayment(product: product) SKPaymentQueue.defaultQueue().addPayment(payment) }else{ let alert = UIAlertView() alert.title = "Alert" alert.message = "Retriving product please wait." alert.addButtonWithTitle("Ok") alert.show() getProductInfo() } } func getProductInfo() { if SKPaymentQueue.canMakePayments() { let request = SKProductsRequest(productIdentifiers: NSSet(objects: self.productID) as Set<NSObject>) request.delegate = self request.start() } else { let alert = UIAlertView() alert.title = "Alert" alert.message = "Please enable In App Purchase in Settings." alert.addButtonWithTitle("Ok") alert.show() } } //3 func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) { var products = response.products if (products.count != 0) { product = products[0] as? SKProduct self.isProductRecive = true println(product) } else { let alert = UIAlertView() alert.title = "Alert" alert.message = "Product not found" alert.addButtonWithTitle("Ok") alert.show() } products = response.invalidProductIdentifiers for product in products { println("Product not found: \(product)") } } // 4 func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) { println("transactions restnetworking") var purchasedItemIDS = [] for transaction in queue.transactions { var t: SKPaymentTransaction = transaction as! SKPaymentTransaction let prodID = t.payment.productIdentifier as String switch prodID { case "com.webstart.tomsgamesinc.StartLight_No_Ads": println("remove ads") default: println("IAP not setup") } } } // 5 func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) { for transaction in transactions as! [SKPaymentTransaction] { switch transaction.transactionState { case .Restonetworking: SKPaymentQueue.defaultQueue().finishTransaction(transaction) case .Purchased: SKPaymentQueue.defaultQueue().finishTransaction(transaction) case .Failed: SKPaymentQueue.defaultQueue().finishTransaction(transaction) default: break } } } func request(request: SKRequest!, didFailWithError error: NSError!) { println("There was an error"); } } 

Y está funcionando bien con mi ID de package de aplicaciones, una identificación de producto, así que chequee amablemente el problema de connection de iTunes.

Este código funciona para mi juego y devuelve cuántos productos hay que comprar. Funciona para xCode 7.1.1.

 var products = [SKProduct]() var product: SKProduct? //StoreKit protocol method. Called when the AppStore responds func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) { var item = response.products if item.count != 0 { for var i = 0; i < item.count; i++ { product = item[i] as SKProduct products.append(product!) } } print("There are \(products.count) items to buy.") }