Could you guys help me to translate the following code into Swift?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"itms://itunes.apple.com
SwiftUI
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>) {
}
}
//how to use
.sheet(isPresented: $showAppAtStore){
StoreView(appID: "12345678")
}
Swift 5
let url = "your app url"
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
else {
// Earlier versions
if UIApplication.shared.canOpenURL(url as URL) {
UIApplication.shared.openURL(url as URL)
}
}
var url = NSURL(string: "itms-apps://itunes.apple.com/app/id1024941703")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
Xcode 6.4