SCommonViewController.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. import CocoaLumberjack
  11. class SCommonViewController: UITableViewController {
  12. @IBOutlet weak var clearCacheButton: UIButton!
  13. let group = DispatchGroup()
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. // Do any additional setup after loading the view.
  17. }
  18. override func didReceiveMemoryWarning() {
  19. super.didReceiveMemoryWarning()
  20. // Dispose of any resources that can be recreated.
  21. }
  22. @IBAction func checkUpdateVersion(_ sender: UIButton) {
  23. self.showLoading(title: "更新校验中,请稍候...")
  24. self.checkAppVersion()
  25. }
  26. private func checkAppVersion() {
  27. O2VersionManager.shared.checkAppUpdate { (info, error) in
  28. self.hideLoading()
  29. if let iosInfo = info {
  30. DDLogDebug(iosInfo.toJSONString() ?? "")
  31. let alertController = UIAlertController(title: "版本更新", message: "更新内容:\(iosInfo.content ?? "")", preferredStyle: .alert)
  32. let okAction = UIAlertAction(title: "确定", style: .default, handler: { ok in
  33. O2VersionManager.shared.updateAppVersion(info?.downloadUrl)
  34. })
  35. let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: { c in
  36. //
  37. })
  38. alertController.addAction(cancelAction)
  39. alertController.addAction(okAction)
  40. UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
  41. }else {
  42. DDLogInfo("没有版本更新:\(error ?? "")")
  43. }
  44. }
  45. }
  46. @IBAction func clearCacheAction(_ sender: UIButton) {
  47. self.showLoading(title: "正在收集...")
  48. let fileSize = SZKCleanCache.folderSizeAtPath()
  49. let msg = "检测到可以清理的缓存大小为\(fileSize)M,是否立即清除?"
  50. let alertController = UIAlertController(title: "", message: msg, preferredStyle: .alert)
  51. let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
  52. self.clearCache()
  53. }
  54. let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
  55. alertController.addAction(okAction)
  56. alertController.addAction(cancelAction)
  57. self.hideLoading()
  58. self.present(alertController, animated: true, completion: nil)
  59. }
  60. private func clearCache() {
  61. self.group.enter()
  62. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  63. Shared.imageCache.removeAll({
  64. SZKCleanCache.cleanCache({
  65. print("图片缓存清除。。。")
  66. self.group.leave()
  67. })
  68. })
  69. }))
  70. self.group.enter()
  71. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  72. let types = WKWebsiteDataStore.allWebsiteDataTypes()
  73. WKWebsiteDataStore.default().removeData(ofTypes: types, modifiedSince: Date(timeIntervalSince1970: 0), completionHandler: {
  74. print("浏览器缓存清除")
  75. self.group.leave()
  76. })
  77. }))
  78. self.group.enter()
  79. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  80. self.clearO2CacheFolder()
  81. print("清除本地缓存目录")
  82. self.group.leave()
  83. }))
  84. self.group.notify(queue: DispatchQueue.main) {
  85. self.showSuccess(title: "清理完成")
  86. self.notify()
  87. }
  88. }
  89. ///清楚本地的缓存文件
  90. private func clearO2CacheFolder() {
  91. O2.deleteFolder(folder: O2.cloudFileLocalFolder())
  92. O2.deleteFolder(folder: O2.base64CacheLocalFolder())
  93. O2.deleteFolder(folder: O2.inforCacheLocalFolder())
  94. }
  95. private func notify() {
  96. // 通知门户页面刷新 因为清除了浏览器缓存 没有cookie了 需要重新加载webview
  97. NotificationCenter.default.post(name: OONotification.reloadPortal.notificationName, object: nil)
  98. }
  99. /*
  100. // MARK: - Navigation
  101. // In a storyboard-based application, you will often want to do a little preparation before navigation
  102. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  103. // Get the new view controller using segue.destinationViewController.
  104. // Pass the selected object to the new view controller.
  105. }
  106. */
  107. }