I solved the problem by referring to @nicolaischneider answer in UIKit.
Present the view controller like this:
guard let scene = UIApplication.shared.windows.first?.windowScene else { return }
let viewController = UIViewController()
let window = UIWindow(windowScene: scene)
window.isHidden = true
window.windowLevel = .normal - 1
window.rootViewController = viewController
window.makeKeyAndVisible()
DispatchQueue.main.async {
self.present(viewController, animated: true)
}
Use purchase(confirmIn:) function:
let result =
if #available(iOS 17.0, *), let scene = await UIApplication.shared.windows.first?.windowScene {
try await product.purchase(confirmIn: scene)
} else {
try await product.purchase()
}
Topic:
App & System Services
SubTopic:
StoreKit
Tags: