75d24c15
yangbin
123
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
//
// MineViewController.swift
// Twear
//
// Created by yangbin on 2021/12/18.
//
import UIKit
import MBProgressHUD
import Alamofire
class MineViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var avatarImageView: UIImageView!
@IBOutlet weak var idLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!
private let mineArray = ["健康报告", "我的数据", "个人资料", "APP检查更新", "关于"]
private let mineDic = ["健康报告": "health_report", "我的数据": "mine_data", "个人资料": "personal_info", "设置": "mine_setting", "APP检查更新": "app_update", "关于": "mine_about"]
private let user = UserInfo
// private var trackViewUrl: String = ""
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
// Do any additional setup after loading the view.
}
private func setupUI() {
let leftButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 28))
leftButton.setTitle(LocString("我的"), for: .normal)
leftButton.titleLabel?.font = BoldFont(18)
leftButton.setTitleColor(.black, for: .normal)
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftButton)
tableView.bounces = false
if let image = UIImage.getImageFromPath("avatar") {
avatarImageView.image = image
} else {
avatarImageView.image = UIImage(named: user.gender == 1 ? "avatar_male" : "avatar_female")
}
if user.name == "" {
nameLabel.text = "\(LocString("用户")):\(user.userId)"
} else {
nameLabel.text = user.name
}
idLabel.text = "id:\(user.userId)"
}
@IBAction func setUserInfo(_ sender: Any) {
let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "UserInfoSettingVC") as! UserInfoSettingVC
vc.modifyClosure = {[weak self] name, image in
if image != nil {
self?.avatarImageView.image = image
}
if name != "" {
self?.nameLabel.text = name
}
}
navigationController?.pushViewController(vc, animated: true)
}
func checkAppVersion() {
MBProgressHUD.showLoading(LocString("正在拼命加载..."), icon: "loading_icon")
let infoDictionary : Dictionary = Bundle.main.infoDictionary!
let curVersion = infoDictionary["CFBundleShortVersionString"] as? String
let path = "https://itunes.apple.com/cn/lookup?id=1601611643"//
var version: String = ""
Alamofire.request(path, method: .post).response { (responseObj) in
if responseObj.error == nil {
let dic:Dictionary = try! JSONSerialization.jsonObject(with: responseObj.data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<String,Any>
if dic["resultCount"] as! Int > 0{
let results:Array = dic["results"] as! Array<Any>
if results.count > 0 {
let resultsDic: Dictionary = results.first as! Dictionary<String,Any>
version = resultsDic["version"] as! String
// let size = resultsDic["fileSizeBytes"] as! Int
let releaseNotes = resultsDic["releaseNotes"] as? String ?? " "
let trackViewUrl = resultsDic["trackViewUrl"] as! String
if curVersion!.checkVersion(version) { //发现新版本
MBProgressHUD.hide()
let updateView = AppVersionView(version: version, detail: releaseNotes)
updateView.clickClosure = { [weak self] in
self?.gotoAppStore(trackViewUrl)
}
updateView.show()
} else {
MBProgressHUD.hide()
MBProgressHUD.showh(LocString("当前已是最新版本"))
}
}
}
}
}
}
func gotoAppStore(_ urlString: String) {
let updateUrl: URL = URL(string: urlString)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(updateUrl, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(updateUrl)
}
}
deinit {
print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
}
}
extension MineViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mineArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MineCell", for: indexPath) as! MineCell
cell.label.text = LocString(mineArray[indexPath.row])
cell.setImageView.image = UIImage(named: mineDic[mineArray[indexPath.row]]!)
if indexPath.row == mineArray.count-1 {
cell.lineView.isHidden = true
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch mineArray[indexPath.row] {
case "APP检查更新":
checkAppVersion()
case "个人资料":
let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "UserInfoSettingVC") as! UserInfoSettingVC
vc.modifyClosure = {[weak self] name, image in
self?.avatarImageView.image = image
self?.nameLabel.text = name
}
navigationController?.pushViewController(vc, animated: true)
case "关于":
let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "AboutAppVC")
navigationController?.pushViewController(vc, animated: true)
case "我的数据":
let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "HealthDataVC")
navigationController?.pushViewController(vc, animated: true)
case "健康报告":
let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "HealthReportVC")
navigationController?.pushViewController(vc, animated: true)
default:
break
}
}
}
|