Search code examples
swiftmacosstorekitswift5

Problems simulating purchase with StoreKit 2


I'm trying to test my IAPs for my macOS app with the new StoreKit 2 API.

I have created a .storekit file and have assigned it in my scheme under Run > Options > StoreKit Configuration.

Retrieving the test products works without problems:

let identifiers = Set(["myProductId"])
let products = try await Product.products(for: identifiers)

But when I want to simulate a purchase nothing happens. It's stuck and never prints the result.

func purchase(product: Product) async throws {
    print("Purchasing \(product.id) ...")
    let result = try await product.purchase()
    print(result)
}

I'm currently on macOS Monterey Beta 8 and Xcode 13 beta 5.


Solution

  • You have to make sure the Sandbox is configured with Outgoing Connections (Client) enabled:

    Sandbox configuration