0

How i use it

import StoreKit

struct StoreView: UIViewControllerRepresentable {

    let appID: String
 
    func makeUIViewController(context: UIViewControllerRepresentableContext<StoreView>) -> SKStoreProductViewController {
        let sKStoreProductViewController = SKStoreProductViewController()
        let parameters = [ SKStoreProductParameterITunesItemIdentifier : appID]
        sKStoreProductViewController.loadProduct(withParameters: parameters)
        return sKStoreProductViewController
        
    }

    func updateUIViewController(_ uiViewController: SKStoreProductViewController, context: UIViewControllerRepresentableContext<StoreView>) {

    }

    func makeCoordinator() -> Coordinator {
        Coordinator()
    }
    
    final class Coordinator: NSObject, SKStoreProductViewControllerDelegate {
        
        func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
            viewController.dismiss(animated: true, completion: nil)
        }
    }
}

I received the following error message: Caught exception during runloop’s autorelease pool drain of client objects SKUnsupportedPresentationException: SKStoreProductViewController must be used in a modal view controller userInfo: (null) 2021-07-19 17:47:58.548221+0800 FlyWind[2858:438420] *** Terminating app due to uncaught exception ‘SKUnsupportedPresentationException’, reason: ‘SKStoreProductViewController must be used in a modal view controller’