WatchKit: How to Check Device Screen Size in Code
The Apple Watch comes in two sizes – the 38mm and the 42mm. This means that you might need to do different logic based on the device screen size in code. In my case, I wanted to set a different image based on the device size.
There are currently two ways to check the Apple Watch device size in code:
Screen Bounds
Use the WKInterfaceDevice
class to get the device bounds:
let currentDevice = WKInterfaceDevice.currentDevice() let bounds = currentDevice.screenBounds // 38mm: (0.0, 0.0, 136.0, 170.0) // 42mm: (0.0, 0.0, 156.0, 195.0) if bounds.width > 136.0 { println("This is the big watch") } else { println("This is the small watch") }
Size Category
The WKInterfaceDevice
class also has a size category option:
let currentDevice = WKInterfaceDevice.currentDevice() let sizeCategory = currentDevice.preferredContentSizeCategory if sizeCategory == "UICTContentSizeCategoryL" { println("This is the big watch") } if sizeCategory == "UICTContentSizeCategoryS" { println("This is the small watch") }
UPDATE: I haven’t had a chance to actually test this on a device (and I only have one watch), but here’s a heads up about the Size Category from @schukin. So make sure to test on an actual device!
@NatashaTheRobot AFAIK, WKInterfaceDevice.preferredContentSizeCategory is broken on Watch hardware (always returns the same value)
— Dave Schukin (@schukin) May 11, 2015
Conclusion
Personally, I really like the idea of using the Size Category, but the fact that it returns a hard-coded String vs an enum really has me nervous and worried. The screen bounds option seems a bit more solid at this point.