你们能帮我把以下代码翻译成Swift吗?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.apple.com/de/app/x-gift/id839686104?mt=8&uo=4"]];
(还是我必须使用此链接:itms://itunes.apple.com/app/id839686104?)
你们能帮我把以下代码翻译成Swift吗?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.apple.com/de/app/x-gift/id839686104?mt=8&uo=4"]];
(还是我必须使用此链接:itms://itunes.apple.com/app/id839686104?)
如果您想在应用商店中打开,请使用
let appstoreUrl = "https://itunes.apple.com/in/app/myapp-test/id11111111?mt=8"
UIApplication.shared.openURL(URL(string: appstoreUrl)!)
如果你想在iTunes商店中使用,
let ituneUrl = "itms-apps://itunes.apple.com/in/app/myapp-test/id11111111?mt=8"
UIApplication.shared.openURL(URL(string: ituneUrl)!)
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>) {
}
}
//如何使用
.sheet(isPresented: $showAppAtStore){
StoreView(appID: "12345678")
}
SKStoreProductViewController
无法嵌入; 在 SwiftUI 中会收到断言崩溃。 - hbkSwift 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)
}
}
针对新版AppStore,只需打开您应用的AppStore链接,并将https
协议替换为itms-apps
协议即可。
Swift 4示例:
if let url = URL(string: "itms-apps://itunes.apple.com/us/app/my-app/id12345678?ls=1&mt=8") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
对我来说,这些答案中的一个都没有起作用。(Swift 4) 应用程序总是打开iTunes Store而不是AppStore。
我不得不按照苹果的这个Q&A所描述的方式将url更改为"http://appstore.com/%Appname%"。
例如像这样
private let APPSTORE_URL = "https://appstore.com/keynote"
UIApplication.shared.openURL(URL(string: self.APPSTORE_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