有些事情在模拟器中无法正常工作。当我在模拟器上时,我想在开发过程中排除它们。有没有办法以编程方式告诉代码是否在模拟器中运行。
答案 0 :(得分:1)
我刚在watchKit中试过这个。
NSString *modelNameStr = [[WKInterfaceDevice currentDevice] name];
NSLog(@"modelNameStr: %@ ...", modelNameStr);
if ([modelNameStr isEqualToString:@"MacBookPro2012"]) {
//device is simulator
}
else
{
//its a real watch?
}
2016-01-25 22:32:12.540 Watch Extension[4275:131894] awakeWithContext ...
2016-01-25 22:32:12.541 Watch Extension[4275:131894] willActivate ...
2016-01-25 22:32:12.595 Watch Extension[4275:131894] modelNameStr: MacBookPro2012 ...