必威体育Betway必威体育官网
当前位置:首页 > IT技术

获取 fir.im 上的版本

时间:2019-08-18 13:13:12来源:IT技术作者:seo实验室小编阅读:55次「手机版」
 

fir.im

/// 获取 fir.im 上的版本
    class func getFirVersion()
    {
        URLsession.shared.dataTask(with: URL.init(string: "http://api.fir.im/APPs/latest/\(firAppId)?api_token=\(firApiToken)")!) { (data, respond, err) in
            
            if data != nil
            {
                do
                {
                    let jsonStr = try JSON(data: data!)
                    
                    let firbuild = jsonStr["build"].rawString()
                    
                    let localBuild = SwifterSwift.appBuild ?? "1"
                    
                    let firVersion = jsonStr["versionShort"].rawString()
                    let localVersion = self.appShortVersionStr()
                    
                    if (firVersion?.compare(localVersion) == .orderedDescending) || (firVersion?.compare(localVersion) == .orderedSame && firBuild?.compare(localBuild) == .orderedDescending)
                    {
                        alertEasily.showAlert(title: "提示", message: "有新的版本,是否要更新?", preferredStyle: .alert, defaultActionTitle: "更新", cancelActionTitle: "取消", defaulthandler: {
                            
                            if let firUpdateUrl = jsonStr["update_url"].rawString()
                            {
                                if let url = URL(string: firUpdateUrl)
                                {
                                    if UIApplication.shared.canOpenURL(url)
                                    {
                                        UIApplication.shared.open(url, options: [ : ], completionHandler: nil)
                                    }
                                }
                                
                                
                            }
                
                            
                        }, cancelHandler: {
                            //取消
                        })
                        
                    }
                    
                }
                catch _ as NSERROR
                {
                    
                }
            }
            
            }.resume()
    }

相关阅读

分享到:

栏目导航

推荐阅读

热门阅读