I've been implementing in app purchases into an existing C++ app. I'm using the latest Swift StoreKit since the old ObjC interface is deprecated . There is a really weird problem where the swift/C++ bridging seems to get into a loop. After the Product structure is retrieved I have the following structure which I use to bridge to C++
public struct storeData
{
public var id : String
public var displayName : String
public var description : String
public var price : String
public var purchased : Bool = false
public var level : Int = 0
}
and this is passed back to the caller as follows
public func getProducts (bridge : StoreBridge) -> [storeData]
{
bridge.products.sort { $0.price > $1.price }
var productList : [storeData] = []
for product in bridge.products
{
let data : storeData = storeData(id: product.id,
displayName: product.displayName,
description: product.description,
price: product.displayPrice,
purchased: bridge.purchasedProductIds.contains(product.id)
)
productList.append(data)
}
return productList
}
the "bridge" variable is a bridging class where the guts of the bridge resides, and contains the "products" array as a publishable variable.
In the C++ code the data is retrieved by
outProd->id = String(inProd.getId());
outProd->displayName = String(inProd.getDisplayName());
outProd->description = String(inProd.getDescription());
outProd->price = String(String(inProd.getPrice()));
outProd->purchased = inProd.getPurchased();
The "String" is actually a JUCE string but that's not part of the problem. Testing this with a local StoreKit config file works fine but when I test with a sandbox AppStore the app hangs. Very specifically it hangs somewhere in the Swift thunk when retrieving the price. When I remove the line to retrieve the price everything works. And - and this is the weird bit - when I pad the price out with some random text, it now starts working (so I have a workaround). This is, however, slightly worrying behaviour. Ideas?