• 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

    Alamofire

    Alamofire

    Alamofire

    Alamofire

    Alamofire

  • 相关阅读:
    二进制数组ArrayBuffer
    iperf3测量一个网络最大带宽
    Proxy与Reflect
    Symbol
    Iterator
    Set与Map
    Generator
    Android 共享参数 SharedPreferences
    DDMS files not found: xxxhprof-conv.exe
    Android 状态栏通知 Notification
  • 原文地址:https://www.cnblogs.com/kunH/p/7340513.html
Copyright © 2020-2023  润新知