SCommonViewController.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // SCommonViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/10/13.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import WebKit
  10. class SCommonViewController: UITableViewController {
  11. @IBOutlet weak var clearCacheButton: UIButton!
  12. let group = DispatchGroup()
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. // Do any additional setup after loading the view.
  16. }
  17. override func didReceiveMemoryWarning() {
  18. super.didReceiveMemoryWarning()
  19. // Dispose of any resources that can be recreated.
  20. }
  21. @IBAction func checkUpdateVersion(_ sender: UIButton) {
  22. PgyUpdateManager.sharedPgy().checkUpdate(withDelegete: self, selector: #selector(updateVersion(_:)))
  23. self.showLoading(title: "更新校验中,请稍候...")
  24. }
  25. @objc private func updateVersion(_ response:AnyObject?){
  26. print("update be callbacked")
  27. if let obj = response {
  28. self.hideLoading()
  29. //print(obj)
  30. let appURLString = obj["downloadURL"]
  31. if let appURL = URL(string: appURLString as! String) {
  32. if UIApplication.shared.canOpenURL(appURL) {
  33. if UIApplication.shared.openURL(appURL) {
  34. PgyUpdateManager.sharedPgy().updateLocalBuildNumber()
  35. }
  36. }
  37. }
  38. }else{
  39. self.showSuccess(title: "已经是最新版本")
  40. }
  41. }
  42. @IBAction func clearCacheAction(_ sender: UIButton) {
  43. self.showLoading(title: "正在收集...")
  44. let fileSize = SZKCleanCache.folderSizeAtPath()
  45. let msg = "检测到可以清理的缓存大小为\(fileSize)M,是否立即清除?"
  46. //let msgAttrib = msg.color(RGB(155, g: 155, b: 155))
  47. let alertController = UIAlertController(title: "", message: msg, preferredStyle: .alert)
  48. let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
  49. self.clearCache()
  50. }
  51. let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
  52. alertController.addAction(okAction)
  53. alertController.addAction(cancelAction)
  54. self.hideLoading()
  55. self.present(alertController, animated: true, completion: nil)
  56. }
  57. private func clearCache() {
  58. self.group.enter()
  59. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  60. Shared.imageCache.removeAll({
  61. SZKCleanCache.cleanCache({
  62. print("图片缓存清除。。。")
  63. self.group.leave()
  64. })
  65. })
  66. }))
  67. self.group.enter()
  68. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  69. let types = WKWebsiteDataStore.allWebsiteDataTypes()
  70. WKWebsiteDataStore.default().removeData(ofTypes: types, modifiedSince: Date(timeIntervalSince1970: 0), completionHandler: {
  71. print("浏览器缓存清除")
  72. self.group.leave()
  73. })
  74. }))
  75. self.group.notify(queue: DispatchQueue.main) {
  76. self.showSuccess(title: "清理完成")
  77. self.notify()
  78. }
  79. }
  80. private func notify() {
  81. // 通知门户页面刷新 因为清除了浏览器缓存 没有cookie了 需要重新加载webview
  82. NotificationCenter.default.post(name: OONotification.reloadPortal.notificationName, object: nil)
  83. }
  84. /*
  85. // MARK: - Navigation
  86. // In a storyboard-based application, you will often want to do a little preparation before navigation
  87. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  88. // Get the new view controller using segue.destinationViewController.
  89. // Pass the selected object to the new view controller.
  90. }
  91. */
  92. }