【问题标题】:Is there a way to tell if my code is running in Apple Watch Simulator or on a real watch有没有办法判断我的代码是在 Apple Watch Simulator 还是在真正的手表上运行
【发布时间】:2016-05-02 14:01:05
【问题描述】:

有些东西在模拟器中无法正常工作。当我在模拟器上时,我想在开发过程中排除它们。有什么方法可以通过编程方式判断代码是否在模拟器中运行。

【问题讨论】:

标签: ios watchkit apple-watch


【解决方案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 ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-15
    • 2016-09-24
    • 1970-01-01
    • 2021-04-16
    • 2011-12-14
    • 2014-07-10
    • 2016-11-12
    • 2020-10-02
    相关资源
    最近更新 更多