有没有办法判断我的代码是在Apple Watch Simulator中运行还是在真实手表

时间:2016-01-26 03:17:31

标签: ios watchkit apple-watch

有些事情在模拟器中无法正常工作。当我在模拟器上时,我想在开发过程中排除它们。有没有办法以编程方式告诉代码是否在模拟器中运行。

1 个答案:

答案 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 ...