| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- //
- // SCommonViewController.swift
- // O2Platform
- //
- // Created by 刘振兴 on 2016/10/13.
- // Copyright © 2016年 zoneland. All rights reserved.
- //
- import UIKit
- import EZSwiftExtensions
- import WebKit
- class SCommonViewController: UITableViewController {
-
- @IBOutlet weak var clearCacheButton: UIButton!
- let group = DispatchGroup()
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
-
-
-
-
- @IBAction func checkUpdateVersion(_ sender: UIButton) {
- PgyUpdateManager.sharedPgy().checkUpdate(withDelegete: self, selector: #selector(updateVersion(_:)))
- ProgressHUD.show("更新校验中,请稍候...", interaction: false)
- }
-
- @objc private func updateVersion(_ response:AnyObject?){
- print("update be callbacked")
- if let obj = response {
- ProgressHUD.dismiss()
- //print(obj)
- let appURLString = obj["downloadURL"]
- if let appURL = URL(string: appURLString as! String) {
- if UIApplication.shared.canOpenURL(appURL) {
- if UIApplication.shared.openURL(appURL) {
- PgyUpdateManager.sharedPgy().updateLocalBuildNumber()
- }
- }
- }
- }else{
- ProgressHUD.show("已经是最新版本")
- Timer.after(0.5, {
- DispatchQueue.main.async {
- ProgressHUD.dismiss()
- }
- })
- }
- }
-
-
- @IBAction func clearCacheAction(_ sender: UIButton) {
- ProgressHUD.show("正在收集...", interaction: false)
- let fileSize = SZKCleanCache.folderSizeAtPath()
- let msg = "检测到可以清理的缓存大小为\(fileSize)M,是否立即清除?"
- //let msgAttrib = msg.color(RGB(155, g: 155, b: 155))
- let alertController = UIAlertController(title: "", message: msg, preferredStyle: .alert)
- let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
- self.clearCache()
- }
-
- let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
- alertController.addAction(okAction)
- alertController.addAction(cancelAction)
- ProgressHUD.dismiss()
- self.present(alertController, animated: true, completion: nil)
-
- }
-
- private func clearCache() {
- self.group.enter()
- DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
- Shared.imageCache.removeAll({
- SZKCleanCache.cleanCache({
- print("图片缓存清除。。。")
- self.group.leave()
- })
- })
- }))
- self.group.enter()
- DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
- let types = WKWebsiteDataStore.allWebsiteDataTypes()
- WKWebsiteDataStore.default().removeData(ofTypes: types, modifiedSince: Date(timeIntervalSince1970: 0), completionHandler: {
- print("浏览器缓存清除")
- self.group.leave()
- })
- }))
-
- self.group.notify(queue: DispatchQueue.main) {
- ProgressHUD.showSuccess("清理完成")
- self.notify()
- }
- }
-
- private func notify() {
- // 通知门户页面刷新 因为清除了浏览器缓存 没有cookie了 需要重新加载webview
- NotificationCenter.default.post(name: Notification.Name("reloadPortal"), object: nil)
- }
-
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
- }
- */
- }
|