On iOS 15 with Xcode 14.3, Product.priceFormatStyle
does not appear to be populated with valid data when running unit tests and setting up an SKTestSession. If I try to access the property in the debugger (po product.priceFormatStyle
) it hangs Xcode indefinitely. If I use a print
statement, I get the following output.
Currency(locale: xx_XX (fixed), currencyCode: "", collection: Foundation.CurrencyFormatStyleConfiguration.Collection(scale: nil, precision: nil, group: nil, signDisplayStrategy: nil, decimalSeparatorStrategy: nil, rounding: nil, roundingIncrement: nil, presentation: Foundation.CurrencyFormatStyleConfiguration.Presentation(option: Foundation.CurrencyFormatStyleConfiguration.Presentation.Option.standard)))
The same output when running on iOS 16 is:
Currency(locale: en_US@currency=USD (fixed), currencyCode: "USD", collection: Foundation.CurrencyFormatStyleConfiguration.Collection(scale: nil, precision: nil, group: nil, signDisplayStrategy: nil, decimalSeparatorStrategy: nil, rounding: nil, roundingIncrement: nil, presentation: Foundation.CurrencyFormatStyleConfiguration.Presentation(option: Foundation.CurrencyFormatStyleConfiguration.Presentation.Option.standard)))
A simple test to replicate the issue is:
let session: SKTestSession = try! SKTestSession(configurationFileNamed: "Subscriptions")
override func setUpWithError() throws {
session.resetToDefaultState()
session.disableDialogs = true
session.clearTransactions()
session.storefront = "USA"
}
func testPriceFormat() async throws {
guard let product = try await Product.products(for: ["test.product"]).first else {
XCTFail()
return
}
XCTAssertEqual(product.priceFormatStyle.currencyCode, "USD") // Fails on iOS 15 with testPriceFormat(): XCTAssertEqual failed: ("") is not equal to ("USD")
}
It seems to be working fine when run on the live app using App Store data; I get the same output on both iOS 15 and 16.
These outputs are using the same test StoreKit configuration. Is there a trick to getting this working for iOS 15?