Search code examples
iosswiftin-app-purchaseapplet

How can fetch ProductIDs in Apple Connect?(In App Purchase)


I'm trying to do fetch ProductIDs. But response always be null. I want to show what I do.

  1. I Create App IDs in developer Account.BundleID equal to AppID
  2. I've installed the project App Connect. Selected my Project BundleID
  3. Created ProductID's
  4. Switch on the In App Purchase in Xcode
  5. My Code:

Created ProductID's:

             `enum IAPProduct: String {
                case Consumble = "com.xxxx.xxx.Consumable"
                case nonConsumble = "com.xxxx.xxx.TekSeferAl"
                       }`

My fetch code:

 class IAPService: NSObject {
static let shared = IAPService()
private override init() {}

//MARK:- Properties
//MARK:- Private

func getProducts() {
    SKPaymentQueue.canMakePayments()
    let products: Set = [IAPProduct.Consumble.rawValue,
                         IAPProduct.nonConsumble.rawValue]
    let request = SKProductsRequest(productIdentifiers: products)
    request.cancel()
    request.delegate  = self
    request.start()

   }
}

Delegate:

 extension IAPService: SKProductsRequestDelegate {
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
    response.invalidProductIdentifiers.forEach { product in
        print("Invalid: \(product)")
    }

    response.products.forEach { product in
        print("Valid: \(product)")

    }
    func request(_ request: SKRequest, didFailWithError error: Error) {
        print("Error for request: \(error.localizedDescription)")
    }
  }
}

Output

enter image description here

Where am I making a mistake?


Solution

  • The problem is that it seems your products are in the state of "Missing Metadata" in App Store Connect - they need to be in "Ready to Submit" for testing.

    You're probably either:

    1. Missing a photo (you can use a blank image for testing)
    2. Haven't signed the the Paid Applications Agreement with Apple

    Here's a good blog post that covers setting up products in more detail: Configuring In-app Products is Hard