I would like to open the app store with my app inside my swiftui app, e.g with sheet.
I found this article Link:
Here are my code for SKStoreProductWithClosure.swift class.
import StoreKit
class ViewController: UIViewController {
let appURL = URL(string: "https://itunes.apple.com/app/idxxxxxxxx")!
let productID = xxxxxxxxx
func openAppStore() {
let appStoreVC = SKStoreProductViewController()
appStoreVC.delegate = self
let parametersDictionary = [SKStoreProductParameterITunesItemIdentifier: productID]
appStoreVC.loadProduct(withParameters: parametersDictionary) { loaded, error in
guard error == nil, loaded else {
return
}
self.present(appStoreVC, animated: true)
}
}
}
extension ViewController: SKStoreProductViewControllerDelegate {
func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
viewController.dismiss(animated: true)
}
}
Here are my current ContentView.
import SwiftUI
struct ContentView: View {
@State private var showAppStore = false
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
.onTapGesture {
self.showAppStore.toggle()
}
.sheet(isPresented: $showAppStore) {
// Here I need the openAppStore() function
}
}
.padding()
}
}
#Preview {
ContentView()
}
But I have big trouble to implement the class into my ContentView. I had some solution but then sheet comes up twice (one blank and after the app store sheet)
May I ask you, give me some help or hints.
Many thanks in advance. Sven
I expect to click on the image and the sheet with the app store content of my app comes up.