Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 795
tounaobun Avatar asked Apr 09 '15 02:04

tounaobun


People also ask

How do I know what Apple Watch version I have?

Tap the My Watch tab and then tap General. Tap About. On this screen, you'll see a section that says Model. It will contain a number in it, but you'll need to tap this number to reveal the model number.

What's the difference between 42mm and 38mm?

Both version offer retina resolutions, but the 42mm packs more pixels with 312 x 390 pixels as compared to the 272 x 340 resolution of the 38mm model. If you want a bigger display and more pixels, then you should purchase the 42mm model.


2 Answers

Your code looks good, but has a few minor issues:

  • You don't have a case for an "unknown" screen size (possibly released in the future)
  • You're using CGRectMake but in Swift you should use a CGRect initializer
  • You're using CGRectEqualToRect but in Swift you can just use == or switch
  • You're explicitly returning WatchResolution enums, but you don't need to be explicit - Swift will figure it out from your method signature
  • You're declaring watch42mmRect but not using it for anything

I would rewrite it like this:

enum WatchResolution {
    case Watch38mm, Watch42mm, Unknown
}

extension WKInterfaceDevice {
    class func currentResolution() -> WatchResolution {
        let watch38mmRect = CGRect(x: 0, y: 0, width: 136, height: 170)
        let watch42mmRect = CGRect(x: 0, y: 0, width: 156, height: 195)

        let currentBounds = WKInterfaceDevice.currentDevice().screenBounds

        switch currentBounds {
        case watch38mmRect:
            return .Watch38mm
        case watch42mmRect:
            return .Watch42mm
        default:
            return .Unknown
        }
    }
}
like image 135
Aaron Brager Avatar answered Nov 16 '22 02:11

Aaron Brager


Update Swift 4:

It includes new launch of Watch resolutions:

enum WatchResolution {
    case Watch38mm, Watch40mm,Watch42mm,Watch44mm, Unknown  
}

extension WKInterfaceDevice {
class func currentResolution() -> WatchResolution {
    let watch38mmRect = CGRect(x: 0, y: 0, width: 136, height: 170)
    let watch40mmRect = CGRect(x: 0, y: 0, width: 162, height: 197)
    let watch42mmRect = CGRect(x: 0, y: 0, width: 156, height: 195)
    let watch44mmRect = CGRect(x: 0, y: 0, width: 184, height: 224)

    let currentBounds = WKInterfaceDevice.current().screenBounds

    switch currentBounds {
    case watch38mmRect:
        return .Watch38mm
    case watch40mmRect:
        return .Watch40mm
    case watch42mmRect:
        return .Watch42mm
    case watch44mmRect:
        return .Watch44mm
    default:
        return .Unknown
    }
  } 
}

Usage

let resol = WKInterfaceDevice.currentResolution()
    switch resol {
    case .Watch38mm, .Watch42mm:
        // Do Something
    case .Watch40mm, .Watch44mm:
        // Do Something
    default:
        // Do Something
    }

Reference Link: Apple Developer Watch Interface Link

Hope that helps....

Thanks

like image 24
Harjot Singh Avatar answered Nov 16 '22 03:11

Harjot Singh