美文网首页
获取 fir.im 上的版本

获取 fir.im 上的版本

作者: 麦志超 | 来源:发表于2019-03-17 10:07 被阅读0次
    /// 获取 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()
        }

    相关文章

      网友评论

          本文标题:获取 fir.im 上的版本

          本文链接:https://www.haomeiwen.com/subject/qvvymqtx.html