Products.product always returns an empty array

Hello,

I'm trying to add in-app purchases to a macOS app but failing to load the local test products. From the docs and various examples I've found online, it should be pretty straightforward with StoreKit 2.

So far, I've done the following:

  • added in-app purchase capability
  • created the local .storekit file
  • added consumable and non-consumable products
  • updated the scheme to use the test StoreKit configuration
  • verified the products are present and can be purchase by using Debug > StoreKit > Manage Transactions to make direct purchases
  • verified the product IDs are correct

To simplify things I tried creating a barebones app. I created a new .storekit file and added a single non-consumable product with ID product1. I used the default view and just a task to retrieve the products:

import SwiftUI
import StoreKit

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .task {
          let products = try? await Product.products(for: ["product1"])
          print(products)
        }
        .padding()
    }
}

The print statement output is: Optional([])

I know I must be doing something wrong, but I'm completely missing it. I hope someone can help me.

Thanks

Accepted Reply

It turned out that there was nothing wrong with my configuration and I didn't need to get the build approved for external testing. My laptop had been on for a few days and, it seems, somehow that it was causing an issue in XCode. When I restarted my laptop, on the first attempt the products were returned. An unusual issue and (somewhat stereotypical) solution.

Replies

I had a similar issue, which you can see in the following post:

https://developer.apple.com/forums/thread/740539

It turns out I had to add a Mac build to my app in TestFlight and get the build approved for external testing to get the products to fetch properly.

  • Hi, thanks for your response. I'm not sure I follow, though. My app is macOS only and already has builds in Test Flight and indeed live. What exactly was the process you had to follow? I thought the point of the local .storekit file was that you didn't need to have anything setup and approved first in App Store Connect in order to build and test.

Add a Comment

It turned out that there was nothing wrong with my configuration and I didn't need to get the build approved for external testing. My laptop had been on for a few days and, it seems, somehow that it was causing an issue in XCode. When I restarted my laptop, on the first attempt the products were returned. An unusual issue and (somewhat stereotypical) solution.