Swift 通过按钮打开应用商店
你们能帮我把下面的代码翻译成Swift吗Swift 通过按钮打开应用商店,swift,app-store,Swift,App Store,你们能帮我把下面的代码翻译成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的基础知识 UIApplicatio
[[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(string: "itms://itunes.apple.com/de/app/x-gift/id839686104?mt=8&uo=4")!)
如果您想在Swift 5中打开应用商店:
if let url = URL(string: "itms-apps://apple.com/app/id839686104") {
UIApplication.shared.open(url)
}
由于其他答案不适用于我(Swift,Xcode 6.1.1),我在这里发布了我的解决方案:
var url = NSURL(string: "itms://itunes.apple.com/de/app/x-gift/id839686104?mt=8&uo=4")
if UIApplication.sharedApplication().canOpenURL(url!) {
UIApplication.sharedApplication().openURL(url!)
}
Xcode 6.4我使用这种组合,它更适合于价格/购物 (部分来自) 不要忘记导入和委派:
import StoreKit
class RateMeViewController: UIViewController, SKStoreProductViewControllerDelegate {
Swift 3语法,并通过“if let”进行了改进
if let url = URL(string: "itms-apps://itunes.apple.com/app/id1024941703"),
UIApplication.shared.canOpenURL(url){
UIApplication.shared.openURL(url)
}
2017年7月5日更新(感谢奥斯卡指出这一点):
查看Swift 3中iTunes上的更新应用程序更新
Swift 4和完成处理程序: 确保更新appStoreUrlPath中的id
func openAppStore() {
if let url = URL(string: "itms-apps://itunes.apple.com/app/id..."),
UIApplication.shared.canOpenURL(url){
UIApplication.shared.open(url, options: [:]) { (opened) in
if(opened){
print("App Store Opened")
}
}
} else {
print("Can't Open URL on Simulator")
}
}
对我来说,这些答案中的任何一个都不起作用。(Swift 4)应用程序总是打开iTunes应用商店而不是应用商店 我不得不将url更改为“”,如本苹果问答中所述: 比如像这样
private let APPSTORE_URL = "https://appstore.com/keynote"
UIApplication.shared.openURL(URL(string: self.APPSTORE_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)
}
您可以在应用程序信息页面上找到应用程序的链接。如果您想在应用程序商店中打开,请使用
let appstoreUrl = "https://itunes.apple.com/in/app/myapp-test/id11111111?mt=8"
UIApplication.shared.openURL(URL(string: appstoreUrl)!)
let ituneUrl = "itms-apps://itunes.apple.com/in/app/myapp-test/id11111111?mt=8"
UIApplication.shared.openURL(URL(string: ituneUrl)!)
如果你想在iTunes商店中使用
let appstoreUrl = "https://itunes.apple.com/in/app/myapp-test/id11111111?mt=8"
UIApplication.shared.openURL(URL(string: appstoreUrl)!)
let ituneUrl = "itms-apps://itunes.apple.com/in/app/myapp-test/id11111111?mt=8"
UIApplication.shared.openURL(URL(string: ituneUrl)!)
在Swift 4.2和Xcode 10.2中 有两种方法可以打开应用商店或iTunes商店 如果您想打开应用商店,请使用https,或者如果您想打开iTunes商店,请使用itms 例如:***4?mt=8//适用于应用商店 itms://itunes.apple.com/in/app/yourAppName/id14****4?mt=8//适用于iTunes商店 方法1:这是一种简单、直接、古老的方法
let url = NSURL(string: "https://itunes.apple.com/in/app/smsdaddy/id1450172544?mt=8")//itms https
if UIApplication.shared.canOpenURL(url! as URL) {
UIApplication.shared.openURL(url! as URL)
}
方法2:新方法
if let url = URL(string: "https://itunes.apple.com/in/app/smsdaddy/id1450172544?ls=1&mt=8") {
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)
}
}
}
斯威夫特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)
}
}
让Swift 5(测试代码)打开应用商店链接
if let url = URL(string: "https://itunes.apple.com/in/app/your-appName/id123456?mt=8")
{
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
else {
if UIApplication.shared.canOpenURL(url as URL) {
UIApplication.shared.openURL(url as URL)
}
}
}
Swift 5.0:
if let url = URL(string: "itms-apps://apple.com/app/id839686104") {
UIApplication.shared.open(url)
}
进口存储套件
extension YourViewController: SKStoreProductViewControllerDelegate {
func openStoreProductWithiTunesItemIdentifier(_ identifier: String) {
let storeViewController = SKStoreProductViewController()
storeViewController.delegate = self
let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, error) -> Void in
if loaded {
self?.present(storeViewController, animated: true, completion: nil)
}
}
}
private func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
viewController.dismiss(animated: true, completion: nil)
}
}
// How to use
openStoreProductWithiTunesItemIdentifier("12345")
迅捷
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>) {
}
}
我知道这不是家庭作业问题,但你仍然需要展示一些效果。这与上面的答案相同,但有不同的URL。StoreKit加1。这是一种比仅仅打开AppStore更好的方式,这是否有效地允许用户将应用“赠送”给第三方?
x-gift
reference?哈,x-gift是我的应用程序名@KatherineJenkinsis,需要“id”,或者我可以只使用带数字的aped吗?可以打开非商店应用程序吗?与内部开发的应用程序一样?仅供参考,这将打开iTunes应用程序商店应用程序,而不是应用程序商店(那么它应该是itms应用程序://
)不错的应用程序商店,但openURL()已被弃用。现在,我们应该将这个应用程序用于相同的行为UIApplication.shared.open(url,选项:[:],completionHandler:nil)您现在还可以将{action=write review}
添加到url字符串中-要直接跳到评级并编写评论…我需要打开我iphone的应用程序商店..在我的应用程序中按rate me按钮。因此,我需要在iphone中的应用商店中打开我的应用程序…我如何处理你的代码..在这里我的帖子…你应该集成以下代码:if let url=url(字符串:Constants.API_REDIRECT_to_ITUNES),UIApplication.shared.canOpenURL(url){UIApplication.shared.open(url,选项:[:],completionHandler:nil)}使用此url而不是Constants.API_REDIRECT_TO_ITUNES:“”但此代码是否会触发应用商店打开或任何浏览器打开…因为我需要应用商店应用程序打开并显示应用程序它将打开应用商店应用程序。什么self.track()
does?在本例中,我打电话给我的分析提供商,添加一条记录,记录用户打开了应用商店。但我只是删除了这条线,因为它是无关的。谢谢你的提问!但是,如果您想更新自己的应用程序,在某些版本的iOS中会失败,因为加载时无法更新应用程序。可惜。什么是标识符字符串?@YogeshPatel是应用程序url中的应用程序ID,下面说的是url,那么应用程序ID将是123456789,好的,明白了。谢谢
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")
}