swiftwatchkitapple-watchdimension

How to tell if current running Apple Watch size/dimension is 38mm or 42mm?


We know that there are two screen sizes for Apple Watch: 38mm and 42mm. The WKInterfaceDevice class provides a readable property named screenBounds. I wrote an extension for WKInterfaceDevice, trying to add a method to detect current device type.

import WatchKit

enum WatchResolution {

    case Watch38mm, Watch42mm
}

extension WKInterfaceDevice {

    class func currentResolution() -> WatchResolution {

        let watch38mmRect = CGRectMake(0.0, 0.0, 136.0, 170.0)
        let watch42mmRect = CGRectMake(0.0, 0.0, 156.0, 195.0)

        let currentBounds = WKInterfaceDevice.currentDevice().screenBounds

        if CGRectEqualToRect(currentBounds, watch38mmRect) {

            return WatchResolution.Watch38mm
        } else {

            return WatchResolution.Watch42mm
        }
    }
}

Is that the correct method to detect Apple Watch size? Is there another method I am missing in the Apple docs?


Solution

  • This is what I am doing:

    enum WatchModel {
        case w38, w40, w42, w44, unknown
    }
    
    extension WKInterfaceDevice {
    
        static var currentWatchModel: WatchModel {
            switch WKInterfaceDevice.current().screenBounds.size {
            case CGSize(width: 136, height: 170):
                return .w38
            case CGSize(width: 162, height: 197):
                return .w40
            case CGSize(width: 156, height: 195):
                return .w42
            case CGSize(width: 184, height: 224):
                return .w44
            default:
                return .unknown
        }
      }
    }