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

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

问题描述

WKInterfaceDevice.current().model 属性没有给出型号:

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

For Apple Watch, the value of this string is 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天全站免登陆