更新时间:2023-12-03 17:32:28
没有公共API可以获取确切的信息.
There is no public API to get that exact information.
不过,您可以使用以下内容(我会让您翻译成Swift):
You can however use the following (I'll let you translate into Swift):
- (NSString*) modelIdentifier {
size_t size = 0;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char* machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString* model = [NSString stringWithCString: machine encoding: NSUTF8StringEncoding];
free(machine);
return model;
}
这将返回格式为"Watch1,1"的字符串.您需要提供一个查找表来执行ID->名称转换.
This returns a string in the format: "Watch1,1". You'll need to provide a lookup table to do ID -> Name translation.
"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
顺便说一句,这个 sysctlbyname
API也适用于iOS.
By the way, this sysctlbyname
API also works for iOS.
干杯.