StoreKit.StoreKitError.unknown thrown by try await Product.products(for: productIdentifiers) using StorekitTest testcases

Viewed 66

StoreKit.StoreKitError.unknown is being thrown by try await Product.products(for: productIdentifiers) when using StoreKitTest.framework to write testcases for In app purchase using the .configuration file.

imported following frameworks in file:

import XCTest
import StoreKitTest

Following code is not throwing any error

do{
    session = try SKTestSession(configurationFileNamed: "IAPSubscriptions")
    session?.resetToDefaultState()
    session?.disableDialogs = true
    session?.clearTransactions()
    XCTAssert(session != nil)
}catch{
    XCTFail("IAPSubscriptions.storekit configuration file could not be loaded")
}

Following code is throwing error:

do{
    let productIdentifier = "com.test.monthly_19"
    let products = try await store.requestWithProductIdentifiers(productIdentifiers: [productIdentifier])
    XCTAssert(products.count  1)
}catch{
    XCTFail() //StoreKit.StoreKitError.unknown
}

How shall I resolve this?

1 Answers

If you see following logs in the console, you may be the same question with me.

[Default] [StoreKit] Failed to get products through appstored in simulator, will try using appstoreagent on host mac: Error Domain=ASDErrorDomain Code=950 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}

[Default][StoreKit] Received error that does not have a corresponding StoreKit Error: Error Domain=ASDErrorDomain Code=950 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}

For my case, only after I set the Host Application to my test target, can it works. Hope it helps to you.

Host Application Setting

Related