swift 获取Appstore版本号并与本地版本比较 更新跳转到Appstore

首先我用的是Alamofire请求的数据

1.获取appstore版本号

func checkVersionTapGestrue(sender: UITapGestureRecognizer){
        Alamofire.request("https://itunes.apple.com/lookup?bundleId=你的bundleId", method: .get, parameters: [:])
            .responseJSON { (response) in
                 
                if let value = response.result.value {
                    let json = JSON(value)
             
                    self.compareVersion(appStoreVersion: json["results"][0]["version"].stringValue)
                }
        }
    }

2.比较两个版本

//比较版本
    func compareVersion(appStoreVersion: String) {
     
        let version:String = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String)!
 
        if appStoreVersion == version {
            BaseController().showTextOnly(view: self.view, text: "当前已经是最新版本", detail: "")
        }else{
            let urlString = "itms-apps://itunes.apple.com/app/id23223232323"(id加你的appId)
            if let url = URL(string: urlString) {
                //根据iOS系统版本,分别处理
                if #available(iOS 10, *) {
                    UIApplication.shared.open(url, options: [:],
                                              completionHandler: {
                                                (success) in
                    })
                } else {
                    UIApplication.shared.openURL(url)
                }
            }
        }
    }   

参考:http://www.hangge.com/blog/cache/detail_1265.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,366评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,283评论 4 61
  • 当你从单身变成恋爱中的女人,幸福也是有时限的,无论你与对方多么合拍,生活到两年以后你会明白你还是独立的个体,他要有...
    变身的小气鬼阅读 517评论 0 0
  • 越来越不知道自己想要的是什么
    amy1222阅读 162评论 0 1
  • 纯白为善, 纯黑为恶, 纯粹的他们 睥睨那伪善的灰。
    果琳劲乖阅读 198评论 0 0