I found a solution.
class AppStoreVC: UIViewController {
let appURL = URL(string: "https://itunes.apple.com/app/idxxxxxxxx")
let productID = xxxxxxxx
func openAppStore() {
let appStoreVC = SKStoreProductViewController()
appStoreVC.delegate = self
let parametersDictionary = [SKStoreProductParameterITunesItemIdentifier: productID]
appStoreVC.loadProduct(withParameters: parametersDictionary) { _, error in
if error != nil {
guard let url = self.appURL else { return }
UIApplication.shared.open(url)
} else {
let scene = UIApplication.shared.connectedScenes.first { $0.activationState == .foregroundActive }
if let windowScene = scene as? UIWindowScene {
windowScene.keyWindow?.rootViewController?.present(appStoreVC, animated: true, completion: nil)
}
}
}
}
}
extension AppStoreVC: SKStoreProductViewControllerDelegate {
func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
viewController.dismiss(animated: true)
}
}
struct ContentView: View {
let appStoreVC = AppStoreVC()
var body: some View {
VStack {
Image(systemName: "apple.logo")
.onTapGesture {
appStoreVC.openAppStore()
}
Text("Open App Store")
}
.padding()
}
}
Post
Replies
Boosts
Views
Activity
I also ask the question in stackoverflow and got the hint not to use .sheet. I should call the openAppStore function directly. Here is my try but I got the following message and no App Store page comes up.
import SwiftUI
struct ContentView: View {
let appStoreProductView = ViewController()
var body: some View {
VStack {
Image(systemName: "apple.logo")
.imageScale(.large)
.onTapGesture {
appStoreProductView.openAppStore()
}
Text("Hello, world!")
}
.padding()
}
}
Xcode message:
Attempt to present <SKStoreProductViewController: 0x10900c200> on <UpdateAppFromPlist.ViewController: 0x104d069c0> (from <UpdateAppFromPlist.ViewController: 0x104d069c0>) whose view is not in the window hierarchy.
I hope, this could be the right direction. Then I don't need struct AppStoreProductView: UIViewControllerRepresentable to create the view.
Many thanks in advance for any kind of help.
Sven
Does no one have any ideas or know what I did wrong?
Top and bottom are ok
I got it. I removed the navigation link inside the lazygrid and put it back outside the lazygrid.
Then I use one navigation link with ispresented. The menu button action and the ontabgesture of the grid item can do the action to activate the navigation link.
That is what I need.
Thank you very much. The solution is great and simple. Now I know :-)
Thanks a million!
Hi, nobody can help me? Please.