Created
April 12, 2017 10:14
-
-
Save shinrikiken/dd8238a96034d5372e55dfb4f5fb1652 to your computer and use it in GitHub Desktop.
Checkversion new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CheckAppVersion.swift | |
// ENEOSPOS | |
// | |
// Created by Than Htike Aung on 12/2/16. | |
// Copyright © 2016 CODIUM. All rights reserved. | |
// | |
import UIKit | |
class CheckAppVersion: NSObject { | |
static var sharedInstance = CheckAppVersion() | |
var isChecking = false | |
func canCheck() -> Bool { | |
let check = self.isChecking | |
if !check { | |
self.isChecking = !check | |
} | |
return check | |
} | |
func checkingAppVersion() { | |
if !self.canCheck() { | |
let appIdentifier = MTConfiguration.appIdentifier() | |
let identifier = appIdentifier.componentsSeparatedByString(".") | |
let appUrl = "\(identifier[identifier.count - 2])-\(identifier[identifier.count - 1])" | |
NSLog("Check App version URL : \(appUrl), uuid : \(Utils.deviceUUID())") | |
let ckeckVersionURL = "\(EndpointURLs.appLatest)\(appUrl)/latest/" | |
APIHandler.get( | |
endpointURL: ckeckVersionURL, | |
isMockAPI: false, | |
params: nil, | |
success: { (response) in | |
let result = response as! [String: AnyObject] | |
let appVersion = result["version"] as! String | |
let downloadURL = result["manifest"] as! String | |
let currentVersion = Utils.getStoreAppVersion() as String | |
self.isChecking = false | |
// different version | |
if appVersion.compare(currentVersion, options: NSStringCompareOptions.NumericSearch, range: nil, locale: nil) == NSComparisonResult.OrderedDescending { | |
let alert = UIAlertController(title: NSLocalizedString("Attention", comment: "Attention"), message: NSLocalizedString("There is new App Version", comment: "There is new App Version"), preferredStyle: UIAlertControllerStyle.Alert) | |
let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: "Cancel"), style: UIAlertActionStyle.Default, handler: nil) | |
let okAction = UIAlertAction(title: NSLocalizedString("Install", comment: "Install"), style: UIAlertActionStyle.Default, handler: { action in | |
NSLog("Download URL : \(downloadURL)") | |
let itmsURL = "itms-services://?action=download-manifest&url=\(downloadURL)" | |
NSLog("itmsURL : \(itmsURL)") | |
UIApplication.sharedApplication().openURL(NSURL(string: itmsURL)!) | |
}) | |
alert.addAction(cancelAction) | |
alert.addAction(okAction) | |
UIApplication.sharedApplication().keyWindow?.rootViewController!.presentViewController(alert, animated: true, completion: nil) | |
} | |
}, failed: { (message, statusCode) in | |
self.isChecking = false | |
NSLog("❗\(self.dynamicType) GET Error: \(message), Status code: \(statusCode)") | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment