如何检查我是否在iPhone6s Plus模拟器上运行

时间:2016-12-04 10:26:02

标签: ios xctest uidevice fbsnapshottestcase

我有每个设备的快照测试。我想检查我的测试,我正在一个特定的模拟器上运行,它有一个快照。

所以例如我想测试当前的模拟器是iPhone6sPlus9.2 因为我没有记录许多其他模拟器类型的快照。

我尝试了许多变体,例如:

(lldb) po [[UIDevice currentDevice] platform]
x86_64

(lldb) po [[UIDevice currentDevice] hwmodel]
MacBookPro11,2

(lldb) po [[UIDevice currentDevice] platformType]
0x0000000000000002

(lldb) po [[UIDevice currentDevice] platformString]
iPhone Simulator

(lldb) po [[UIDevice currentDevice] model]
iPhone

(lldb) po [[UIDevice currentDevice] localizedModel]
iPhone

(lldb) po [[UIDevice currentDevice] systemName]
iPhone OS

(lldb) po [[UIDevice currentDevice] systemVersion]
9.2

(lldb) po [UIDevice currentDevice]
<UIDevice: 0x7fccf060a480>

(lldb) po [[UIDevice currentDevice] name]
iPhone Simulator // I WANT TO KNOW THAT IT IS IPHONE6SPLUS 9.2

以及此处的代码https://github.com/erica/uidevice-extension/

和来自

的代码

// UIDevice + YYAdd.h // YYKit https://github.com/ibireme/YYKit

但两者都返回不相关的值,例如设备类型的“x86”。

1 个答案:

答案 0 :(得分:0)

尝试[NSProcessInfo processInfo].environment[@"SIMULATOR_MODEL_IDENTIFIER"]

它将为iPhone6s Plus模拟器返回iPhone8,2

注意:您可能有理由针对特定的模拟器模型编写代码,但这通常不是一个好主意。您应该动态调整屏幕大小,检查API /框架的可用性等等......