Stephen
Stephen

Reputation: 1446

Detect user's watchOS version from iOS app

I have an iOS app where I have some settings in the iOS app related to the watch. I only want to show them if the user has an Apple Watch that's compatible with my app.

In WatchConnectivity I can query WCSession's isPaired property to see if the user has a watch but I can't figure out how to determine the watchOS version (it needs to be >5.0 to use my app).

Is there a way to determine the watchOS version from the iOS app?

Upvotes: 23

Views: 1654

Answers (2)

asyncawait
asyncawait

Reputation: 704

If the settings only apply if the user has your watch app installed, you probably just want to check that directly using WCSessions isWatchAppInstalled property.

Things get much trickier if you want to get the paired watch's OS version regardless of whether your app is installed. If the user runs the watch app, you could just grab the version on the watch side and send it over (with updateApplicationContext(_:)). Otherwise, there's no way that I know of to get the watchOS version -- and that kind of makes sense. From a platform security perspective, if the user hasn't installed your app then the details of their watch are kind of none of your business.

Upvotes: 3

117MasterChief96
117MasterChief96

Reputation: 568

Here are two possible solutions. Number 1 checks for the OS which if I understand your question you already know, but then 2 checks for the OS version which is WatchOS 5.0 and later. This is what I have done so I hope it helps you.

1.

#if os(watchOS)
    ...your code          
#endif
  1. if #available(watchOS 5.0, *) {
        ...your code
    }
    

Upvotes: -1

Related Questions