首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >通过按钮打开AppStore

通过按钮打开AppStore
EN

Stack Overflow用户
提问于 2014-09-17 13:30:52
回答 15查看 85.1K关注 0票数 67

你们能帮我把下面的代码翻译成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?)

提前感谢!

EN

回答 15

Stack Overflow用户

回答已采纳

发布于 2014-09-17 15:48:24

这里。但我强烈建议您学习Swift的基础知识!

UIApplication.sharedApplication().openURL(NSURL(string: "itms://itunes.apple.com/de/app/x-gift/id839686104?mt=8&uo=4")!)

如果你想在Swift 5中打开AppStore

if let url = URL(string: "itms-apps://apple.com/app/id839686104") {
    UIApplication.shared.open(url)
}
票数 112
EN

Stack Overflow用户

发布于 2016-11-05 11:42:02

Swift 3语法,并使用'if let‘进行了改进

if let url = URL(string: "itms-apps://itunes.apple.com/app/id1024941703"),
UIApplication.shared.canOpenURL(url){
    UIApplication.shared.openURL(url)
}

更新7/5/17 (谢谢你指出这一点):

if let url = URL(string: "itms-apps://itunes.apple.com/app/id1024941703"),
    UIApplication.shared.canOpenURL(url)
{
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    } else {
        UIApplication.shared.openURL(url)
    }
}
票数 72
EN

Stack Overflow用户

发布于 2016-04-12 05:43:57

我使用这个组合,它对价格/购物更好。

(部分来自here)

    @IBAction func rateMe(sender: AnyObject) {
    if #available(iOS 8.0, *) {
        openStoreProductWithiTunesItemIdentifier("107698237252");
    } else {
        var url  = NSURL(string: "itms://itunes.apple.com/us/app/xxxxxxxxxxx/id107698237252?ls=1&mt=8")
        if UIApplication.sharedApplication().canOpenURL(url!) == true  {
            UIApplication.sharedApplication().openURL(url!)
        }

    }
}
func openStoreProductWithiTunesItemIdentifier(identifier: String) {
    let storeViewController = SKStoreProductViewController()
    storeViewController.delegate = self

    let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
    storeViewController.loadProductWithParameters(parameters) { [weak self] (loaded, error) -> Void in
        if loaded {
            // Parent class of self is UIViewContorller
            self?.presentViewController(storeViewController, animated: true, completion: nil)
        }
    }
}
func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
    viewController.dismissViewControllerAnimated(true, completion: nil)
}

别忘了导入和委派:

import StoreKit

class RateMeViewController: UIViewController, SKStoreProductViewControllerDelegate {
票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25882936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档