I am experiencing the same issue, but have another piece of the puzzle. I'm using StoreKit2 in a common component across a SwiftUI app and a Share Extension. The latter necessitates that it is a UIKit controller that then loads and calls out to the common SwiftUI components. To put it another way, the UIKit extension does nothing except handle files shared into it, and then passing the data to the appropriate SwiftUI view(s).
Anyway, my common purchase button, which has worked in both contexts for months, now all of a sudden stopped working in the UIKit extension context. Nothing about these have changed, and I know the purchase code works because the same button is used in the SwiftUI app when not running as an extension, and works fine.
The error I'm getting is the same as the parent more or less: "Could not find a UI anchor for <product id> purchase." In my UIKit code, I define anchors like this to spawn the SwiftUI view:
// Method to display SwiftUI View initially with placeholder content
private func showSwiftUIView(with imageData: ImageData) {
// Create the SwiftUI content view
let contentView = QuickSendApp(imageData: imageData)
// Wrap it in a hosting controller
let hostingController = UIHostingController(rootView: contentView)
// Add the hosting controller as a child
addChild(hostingController)
// Add the hosting controller's view as a subview
hostingController.view.frame = view.bounds
hostingController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(hostingController.view)
// Notify the hosting controller that it was moved to the parent
hostingController.didMove(toParent: self)
// Store a reference to the hosting controller
self.hostingController = hostingController
// Add an observer to close the share extension
NotificationCenter.default.addObserver(forName: NSNotification.Name("close"), object: nil, queue: nil) { [weak self] _ in
self?.closeShareExtension()
}
}
Because I know the purchase handling works fine, I can only assume there's a breakdown here between the SwiftUI code knowing its bounds and where it can run, and the UIKit code defining the frame for it to run within.