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()
}