Saviz
Saviz

Reputation: 687

Is there a way to tell if my code is running in Apple Watch Simulator or on a real watch

There are somethings that don't work correctly in the simulator. I'd like exclude them during my development when I'm on the simulator. Is there any way programmatically I can tell if the code is running in the simulator or not.

Upvotes: 2

Views: 176

Answers (1)

Sam B
Sam B

Reputation: 27598

I just tried this in 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 ...

Upvotes: 1

Related Questions