private func getWatchName(model: String) -> String {
switch model {
case "Watch1,1":
return "Apple Watch Series 0 38mm"
case "Watch1,2":
return"Apple Watch Series 0 42mm"
case "Watch2,3":
return "Apple Watch Series 2 38mm"
case "Watch2,4":
return "Apple Watch Series 2 42mmm"
case "Watch2,6":
return "Apple Watch Series 1 38mm"
case "Watch2,7":
return "Apple Watch Series 1 42mm"
case "Watch3,1":
return "Apple Watch Series 3 38mm Cellular"
case "Watch3,2":
return "Apple Watch Series 3 42mm Cellular"
case "Watch3,3":
return "Apple Watch Series 3 38mm"
case "Watch3,4":
return "Apple Watch Series 3 42mm"
case "Watch4,1":
return "Apple Watch Series 4 40mm"
case "Watch4,2":
return "Apple Watch Series 4 44mm"
case "Watch4,3":
return "Apple Watch Series 4 40mm Cellular"
case "Watch4,4":
return "Apple Watch Series 4 44mm Cellular"
case "Watch5,1":
return "Apple Watch Series 5 40mm"
case "Watch5,2":
return "Apple Watch Series 5 44mm"
case "Watch5,3":
return "Apple Watch Series 5 40mm Cellular"
case "Watch5,4":
return "Apple Watch Series 5 44mm Cellular"
case "Watch5,9":
return "Apple Watch SE 40mm"
case "Watch5,10":
return "Apple Watch SE 44mm"
case "Watch5,11":
return "Apple Watch SE 40mm Cellular"
case "Watch5,12":
return "Apple Watch SE 44mm Cellular"
case "Watch6,1":
return "Apple Watch Series 6 40mm"
case "Watch6,2":
return "Apple Watch Series 6 44mm"
case "Watch6.3":
return "Apple Watch Series 6 40mm Cellular"
case "Watch6,4":
return "Apple Watch Series 6 44mm Cellular"
case "Watch6,6":
return "Apple Watch Series 7 41mm"
case "Watch6,7":
return "Apple Watch Series 7 45mm"
case "Watch6,8":
return "Apple Watch Series 7 41mm Cellular"
case "Watch6,9":
return "Apple Watch Series 7 45mm Cellular"
default:
return "unknown"
}
}
"Watch1,1" -> Apple Watch 38mm
"Watch1,2" -> Apple Watch 42mm
"Watch2,3" -> Apple Watch Series 2 38mm
"Watch2,4" -> Apple Watch Series 2 42mm
"Watch2,6" -> Apple Watch Series 1 38mm
"Watch2,7" -> Apple Watch Series 1 42mm
"Watch3,1" -> Apple Watch Series 3 38mm Cellular
"Watch3,2" -> Apple Watch Series 3 42mm Cellular
"Watch3,3" -> Apple Watch Series 3 38mm
"Watch3,4" -> Apple Watch Series 3 42mm
public func getWatchModel() -> String? {
var size: size_t = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](repeating: 0, count: size)
sysctlbyname("hw.machine", &machine, &size, nil, 0)
return String(cString: &machine, encoding: String.Encoding.utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
}
public func getWatchName(model: String) -> String {
switch model {
case "Watch1,1":
return "Apple Watch Series 0 38mm"
case "Watch1,2":
return"Apple Watch Series 0 42mm"
case "Watch2,3":
return "Apple Watch Series 2 38mm"
case "Watch2,4":
return "Apple Watch Series 2 42mmm"
case "Watch2,6":
return "Apple Watch Series 1 38mm"
case "Watch2,7":
return "Apple Watch Series 1 42mm"
case "Watch3,1":
return "Apple Watch Series 3 38mm Cellular"
case "Watch3,2":
return "Apple Watch Series 3 42mm Cellular"
case "Watch3,3":
return "Apple Watch Series 3 38mm"
case "Watch3,4":
return "Apple Watch Series 3 42mm"
case "Watch4,1":
return "Apple Watch Series 4 40mm"
case "Watch4,2":
return "Apple Watch Series 4 44mm"
case "Watch4,3":
return "Apple Watch Series 4 40mm Cellular"
case "Watch4,4":
return "Apple Watch Series 4 44mm Cellular"
case "Watch5,1":
return "Apple Watch Series 5 40mm"
case "Watch5,2":
return "Apple Watch Series 5 44mm"
case "Watch5,3":
return "Apple Watch Series 5 40mm Cellular"
case "Watch5,4":
return "Apple Watch Series 5 44mm Cellular"
case "Watch5,9":
return "Apple Watch SE 40mm"
case "Watch5,10":
return "Apple Watch SE 44mm"
case "Watch5,11":
return "Apple Watch SE 40mm Cellular"
case "Watch5,12":
return "Apple Watch SE 44mm Cellular"
case "Watch6,1":
return "Apple Watch Series 6 40mm"
case "Watch6,2":
return "Apple Watch Series 6 44mm"
case "Watch6.3":
return "Apple Watch Series 6 40mm Cellular"
case "Watch6,4":
return "Apple Watch Series 6 44mm Cellular"
case "Watch6,6":
return "Apple Watch Series 7 41mm"
case "Watch6,7":
return "Apple Watch Series 7 45mm"
case "Watch6,8":
return "Apple Watch Series 7 41mm Cellular"
case "Watch6,9":
return "Apple Watch Series 7 45mm Cellular"
case "x86_64":
return "Apple Watch Series 9 Simulator"
default:
return "unknown"
}
}
4条答案
按热度按时间cxfofazt1#
只是稍微更新了WatchOS 6和苹果手表系列5的@Mathieu Vandeginste答案。
这需要对WatchOS 5进行一项更改,以从
getWatchModel()
中修剪原始字符串,因为它现在使用以下选项卡结束:?.trimmingCharacters(in: .whitespacesAndNewlines)
刚刚在this article的基础上添加了新型号
5uzkadbs2#
没有公共API可以获取确切的信息。
但是,您可以使用以下代码(我会让您翻译成Swift):
这将返回以下格式的字符串:“Watch 1,1”。您需要提供一个查找表来进行ID -〉Name转换。
顺便说一下,这个
sysctlbyname
API也适用于iOS。干杯。
mkshixfv3#
编辑:不再适用于watchOS 4+
这是Swift 4+版本:对我来说很好:)
7dl7o3gd4#
针对watchOS 8和Apple Watch系列7进行了更新
其他答案说这不起作用,因为函数返回
Watc\t
,这修复了它。