swiftin-app-purchaseskproduct

swift In App Purchase issue with SKProduct


I'm making an app with some IAP and I'm facing a boring issue which makes me feel insane.. I tested my IAP but it didn't work. (nothing happenned) I checked what's wrong and found the problem comes from the SKProduct. So I'm trying to request a Product with SKProductsRequest(productIdentifiers: productIds) and then if I print: response.products.count , the result will be 0. (response:SKProductsResponse)

Here's my code to request the product :

class IAPHandler: NSObject {
static let shared = IAPHandler()

fileprivate var productID = ""
public var productIdentifiers:NSSet = ["com.company.app.IAP1","com.company.app.IAP2"]
public var iapProducts = [SKProduct]()
var productsRequest = SKProductsRequest()

var purchaseStatusBlock: ((IAPHandlerAlertType) -> Void)?


func canMakePurchases() -> Bool {  return SKPaymentQueue.canMakePayments()  }

func purchaseMyProduct(index: Int){

    print(iapProducts.count)

    if iapProducts.count == 0 { return } .    //// return 0 !

    if self.canMakePurchases() { .   //// return true

        let product = iapProducts[index]
        let payment = SKPayment(product: product)
        SKPaymentQueue.default().add(self)
        SKPaymentQueue.default().add(payment)


        productID = product.productIdentifier
    } else {

        purchaseStatusBlock?(.disabled)
    }
}  

 func fetchAvailableProducts(){

    productsRequest = SKProductsRequest(productIdentifiers: productIdentifiers as! Set<String>)

    productsRequest.delegate = self
    productsRequest.start()
  }
} 

But response.product do not catch any values..

Does someone know what does it mean if my result is equal to 0? please help me to figure it out this issues. Do not hesitate to ask me more informations.


Solution

  • OK the answer is so simple..Someone told me to set the "agreements, tax and banking" Itunes connect informations... Now it works like a charm!