【发布时间】:2020-02-13 04:29:23
【问题描述】:
我已经搜索了一段时间,发现无法从UIDevice.current.model 获取,因为它只返回iPhone。有几个答案指向此代码:
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] {
return simulatorModelIdentifier
}
var sysinfo = utsname()
uname(&sysinfo) // ignore return value
let deviceModel = String(bytes: Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN)), encoding: .ascii)?.trimmingCharacters(in: .controlCharacters)
return deviceModel ?? ""
顺便说一句,我不确定这是使用公共 api 还是私有 api,它对我来说似乎是私有 api。
问题 此代码是否使用任何私有 api?
【问题讨论】:
-
你检查过这个答案吗? stackoverflow.com/a/11197770/6678991
-
您检查了@Mahdi-Malv 所附问题中的所有答案吗?有正确的解决方案来获取正确的代码以及从代码到模型名称的映射。
-
是的,我已经赞成@Mahdi-Malv 的评论。顺便说一句,我只想知道盖尔的答案
标签: ios swift iphone-privateapi