如何确定Apple Watch型号? [英] How to determine the Apple Watch model?

查看:150
本文介绍了如何确定Apple Watch型号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WKInterfaceDevice.current().model 属性未提供型号:

对于Apple Watch,此字符串的值为 Apple Watch .

如何从iOS确定确切的Apple Watch型号?

How can the exact Apple Watch model be determined from iOS?

推荐答案

没有公共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.

干杯.

这篇关于如何确定Apple Watch型号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆