Search code examples
ioswatchkitapple-watch

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.


Solution

  • 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 ...