Skip to content

Commit bd6f5ef

Browse files
author
DevelopLab
committed
1. Fix grammar and spelling errors
1 parent 97d9db0 commit bd6f5ef

7 files changed

+59
-19
lines changed

BatteryInfo/Localizable.xcstrings

+2-2
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@
938938
}
939939
}
940940
},
941-
"ForceShowChargeingData" : {
941+
"ForceShowChargingData" : {
942942
"localizations" : {
943943
"en" : {
944944
"stringUnit" : {
@@ -1214,7 +1214,7 @@
12141214
}
12151215
}
12161216
},
1217-
"NeedRunTimePremissionMessage" : {
1217+
"NeedRunTimePermissionMessage" : {
12181218
"localizations" : {
12191219
"en" : {
12201220
"stringUnit" : {

BatteryInfo/Utils/SettingsUtils.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SettingsUtils {
1616
}
1717

1818
enum RecordFrequency: Int {
19-
case Toogle = 0 // 禁用的时候下面的值变成负数,启用的时候是正数
19+
case Toggle = 0 // 禁用的时候下面的值变成负数,启用的时候是正数
2020
case Automatic = 1 // 自动,每天或者电池剩余容量发生变化或者电池循环次数变化时保存
2121
case DataChanged = 2 // 数据发生改变时记录,电池剩余容量发生变化或者电池循环次数变化时保存
2222
case EveryDay = 3 // 每天打开App的时候记录
@@ -45,12 +45,12 @@ class SettingsUtils {
4545
plistManager.apply()
4646
}
4747

48-
func getForceShowChargeingData() -> Bool {
49-
return plistManager.getBool(key: "ForceShowChargeingData", defaultValue: false)
48+
func getForceShowChargingData() -> Bool {
49+
return plistManager.getBool(key: "ForceShowChargingData", defaultValue: false)
5050
}
5151

52-
func setForceShowChargeingData(value: Bool) {
53-
plistManager.setBool(key: "ForceShowChargeingData", value: value)
52+
func setForceShowChargingData(value: Bool) {
53+
plistManager.setBool(key: "ForceShowChargingData", value: value)
5454
plistManager.apply()
5555
}
5656

BatteryInfo/Utils/SystemInfoUtils.swift

+40
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,45 @@ func getDiskTotalSpace() -> String {
117117
return closestSize >= 1024 ? "\(Int(closestSize / 1024)) TB" : "\(Int(closestSize)) GB"
118118
}
119119

120+
// 获取设备的型号代码
121+
func getDeviceRegionCode() -> String? {
122+
let path = "/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/com.apple.MobileGestalt.plist"
123+
124+
// 读取 plist 文件
125+
guard let dict = NSDictionary(contentsOfFile: path) as? [String: Any] else {
126+
NSLog("Battery Info----> 无法加载 MobileGestalt.plist")
127+
return nil
128+
}
129+
130+
// 获取 `CacheExtra` 字典
131+
guard let cacheExtra = dict["CacheExtra"] as? [String: Any] else {
132+
NSLog("Battery Info----> MobileGestalt无法找到 `CacheExtra` 字典")
133+
return nil
134+
}
135+
136+
// 先尝试直接获取 `zHeENZu+wbg7PUprwNwBWg`
137+
if let regionCode = cacheExtra["zHeENZu+wbg7PUprwNwBWg"] as? String {
138+
if isValidRegionCode(regionCode) {
139+
return regionCode
140+
}
141+
}
142+
143+
// 遍历 `CacheExtra` 并匹配设备型号代码格式
144+
for (key, value) in cacheExtra {
145+
if let regionCode = value as? String, isValidRegionCode(regionCode) {
146+
NSLog("Battery Info----> MobileGestalt未找到默认 key,使用遍历找到的 key: \(key) -> \(regionCode)")
147+
return regionCode
148+
}
149+
}
150+
return nil
151+
}
152+
153+
// 匹配设备发售型号格式
154+
private func isValidRegionCode(_ code: String) -> Bool {
155+
let pattern = "^[A-Z]{2}/A$" // 匹配 XX/A 格式,例如 CH/A、LL/A、ZA/A
156+
return code.range(of: pattern, options: .regularExpression) != nil
157+
}
158+
120159
func getDeviceName() -> String {
121160
switch getDeviceModel() {
122161

@@ -170,6 +209,7 @@ func getDeviceName() -> String {
170209
case "iPhone17,2": return "iPhone 16 Pro Max"
171210
case "iPhone17,3": return "iPhone 16"
172211
case "iPhone17,4": return "iPhone 16 Plus"
212+
case "iPhone17,5": return "iPhone 16e" // 新2025.2.19 新增iPhone 16e
173213

174214
// iPod
175215
case "iPod1,1": return "iPod Touch (1st Gen)"

BatteryInfo/ViewController/AllBatteryDataViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class AllBatteryDataViewController: UIViewController, UITableViewDataSource, UIT
8282
case 1: return 2
8383
case 2: return 3
8484
case 3:
85-
if SettingsUtils.instance.getForceShowChargeingData() {
85+
if SettingsUtils.instance.getForceShowChargingData() {
8686
return 8
8787
} else if isDeviceCharging() {
8888
if chargerHaveName() {

BatteryInfo/ViewController/DataRecordSettingsViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class DataRecordSettingsViewController: UIViewController, UITableViewDelegate, U
151151
@objc func onSwitchChanged(_ sender: UISwitch) {
152152

153153
if sender.tag == 0 { // 启用的开关
154-
settingsUtils.setRecordFrequency(value: .Toogle) // 切换启用的开关
154+
settingsUtils.setRecordFrequency(value: .Toggle) // 切换启用的开关
155155
} else if sender.tag == 1 {
156156
settingsUtils.setShowHistoryRecordViewInHomeView(value: sender.isOn) // 切换显示在主界面的开关
157157
reloadMainTabBar = true // 更改刷新标记

BatteryInfo/ViewController/HomeViewController.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDe
1313
private var refreshTimer: Timer?
1414
private var showOSBuildVersion = false
1515

16-
private var allDatainSection = 4
16+
private var allDataInSection = 4
1717

1818
override func viewDidLoad() {
1919
super.viewDidLoad()
@@ -56,7 +56,7 @@ class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDe
5656
if !BatteryDataController.checkRunTimePermission() {
5757

5858
if !BatteryDataController.checkInstallPermission() {
59-
let alert = UIAlertController(title: NSLocalizedString("Alert", comment: ""), message: NSLocalizedString("NeedRunTimePremissionMessage", comment: ""), preferredStyle: .alert)
59+
let alert = UIAlertController(title: NSLocalizedString("Alert", comment: ""), message: NSLocalizedString("NeedRunTimePermissionMessage", comment: ""), preferredStyle: .alert)
6060
alert.addAction(UIAlertAction(title: NSLocalizedString("Dismiss", comment: ""), style: .cancel))
6161
present(alert, animated: true)
6262

@@ -130,10 +130,10 @@ class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDe
130130
// MARK: - 设置总分组数量
131131
func numberOfSections(in tableView: UITableView) -> Int {
132132
if settingsUtils.getShowSettingsBatteryInfo() {
133-
allDatainSection = 4
133+
allDataInSection = 4
134134
return 5
135135
} else {
136-
allDatainSection = 3
136+
allDataInSection = 3
137137
return 4
138138
}
139139
}
@@ -149,7 +149,7 @@ class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDe
149149
return 2
150150
case 1: return 9 // 电池信息
151151
case 2: // 充电信息
152-
if settingsUtils.getForceShowChargeingData() {
152+
if settingsUtils.getForceShowChargingData() {
153153
return 11
154154
} else {
155155
if isDeviceCharging() || isChargeByWatts() {
@@ -444,7 +444,7 @@ class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDe
444444
}
445445
}
446446

447-
if indexPath.section == allDatainSection {
447+
if indexPath.section == allDataInSection {
448448
cell.accessoryType = .disclosureIndicator
449449
if indexPath.row == 0 { // 显示全部数据
450450
cell.textLabel?.text = NSLocalizedString("AllData", comment: "")
@@ -462,7 +462,7 @@ class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDe
462462
if indexPath.section == 0 && indexPath.row == 0 {
463463
self.showOSBuildVersion = !showOSBuildVersion
464464
tableView.reloadRows(at: [indexPath], with: .none)
465-
} else if indexPath.section == allDatainSection {
465+
} else if indexPath.section == allDataInSection {
466466
if indexPath.row == 0 { // 显示全部数据
467467
let allBatteryDataViewController = AllBatteryDataViewController()
468468
allBatteryDataViewController.hidesBottomBarWhenPushed = true // 隐藏底部导航栏

BatteryInfo/ViewController/SettingsViewController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
1111

1212
private let tableTitleList = [nil, NSLocalizedString("MaximumCapacityAccuracy", comment: ""), NSLocalizedString("About", comment: "")]
1313

14-
private let tableCellList = [[NSLocalizedString("AutoRefreshDataViewSetting", comment: ""), NSLocalizedString("ForceShowChargeingData", comment: ""), NSLocalizedString("ShowSettingsBatteryInfo", comment: ""), NSLocalizedString("DataRecordSettings", comment: "")], [NSLocalizedString("KeepOriginal", comment: ""), NSLocalizedString("Ceiling", comment: ""), NSLocalizedString("Round", comment: ""), NSLocalizedString("Floor", comment: "")], [NSLocalizedString("Version", comment: ""), "GitHub", NSLocalizedString("ThanksForXiaoboVlog", comment: "")]]
14+
private let tableCellList = [[NSLocalizedString("AutoRefreshDataViewSetting", comment: ""), NSLocalizedString("ForceShowChargingData", comment: ""), NSLocalizedString("ShowSettingsBatteryInfo", comment: ""), NSLocalizedString("DataRecordSettings", comment: "")], [NSLocalizedString("KeepOriginal", comment: ""), NSLocalizedString("Ceiling", comment: ""), NSLocalizedString("Round", comment: ""), NSLocalizedString("Floor", comment: "")], [NSLocalizedString("Version", comment: ""), "GitHub", NSLocalizedString("ThanksForXiaoboVlog", comment: "")]]
1515
// NSLocalizedString("ShowCPUFrequency", comment: "")
1616

1717
// 标记一下每个分组的编号,防止新增一组还需要修改好几处的代码
@@ -92,7 +92,7 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
9292
if indexPath.row == 0 {
9393
switchView.isOn = SettingsUtils.instance.getAutoRefreshDataView()
9494
} else if indexPath.row == 1 {
95-
switchView.isOn = SettingsUtils.instance.getForceShowChargeingData()
95+
switchView.isOn = SettingsUtils.instance.getForceShowChargingData()
9696
} else if indexPath.row == 2 {
9797
switchView.isOn = SettingsUtils.instance.getShowSettingsBatteryInfo()
9898
}
@@ -168,7 +168,7 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
168168
if sender.tag == 0 {
169169
SettingsUtils.instance.setAutoRefreshDataView(value: sender.isOn)
170170
} else if sender.tag == 1 {
171-
SettingsUtils.instance.setForceShowChargeingData(value: sender.isOn)
171+
SettingsUtils.instance.setForceShowChargingData(value: sender.isOn)
172172
} else if sender.tag == 2 {
173173
SettingsUtils.instance.setShowSettingsBatteryInfo(value: sender.isOn)
174174
}

0 commit comments

Comments
 (0)