WKInterfaceDevice.current().model
属性没有给出型号:
如何从 iOS 确定确切的 Apple Watch 型号?
最佳答案
没有公共(public) API 可以获取该确切信息。
但是,您可以使用以下内容(我会让您翻译成 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 -> 名称转换。
"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。干杯。
关于ios - 如何确定 Apple Watch 型号?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49087330/