/// 获取 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()
}
网友评论