22

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?

Stephen
  • 1,427
  • 1
  • 17
  • 42
  • 1
    I do not think you can check the watchOS version from iOS. However, you could communicate between the watch app from iOS app to get information you need. – Lei Zhang Oct 29 '19 at 15:52
  • Thanks but I'm still not able to tell the difference between a user who has a watch on watchOS 4 and can't install the watch app vs a user on watchOS 5 that can install the watch app but hasn't – Stephen Oct 30 '19 at 17:33
  • @Stephen try to get from bluetooth info you are interested in [Link1](https://stackoverflow.com/a/51456455/4261814) [Link2](https://stackoverflow.com/a/51147824/4261814) – George Jan 07 '20 at 23:33
  • interesting idea, unfortunately the watch seems to have special handling where it's not available through the standard bluetooth methods – Stephen Jan 08 '20 at 16:52
  • Why don't you just restrict the watchOS ```Deployment Target``` to be 5.0 ? – Starsky Jan 13 '20 at 16:05
  • That is the restriction. I have watch specific settings I want to show in my iOS app. I want to hide them if the user has watchOS 4 but I have no way of knowing if they can install the app successfully or not – Stephen Jan 13 '20 at 20:22
  • This doesn't seem to be possible so I've submitted feedback to Apple: FB7534158 – Stephen Jan 14 '20 at 00:20

2 Answers2

2

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.

asyncawait
  • 575
  • 1
  • 9
-1

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
    }
    
117MasterChief96
  • 548
  • 1
  • 5
  • 16
  • This does not work when running in an iOS app, only when already on an installed watchOS app – Stephen Oct 25 '19 at 19:20
  • Ahh, I did not think about that. Sorry. What if you checked the targetEnvironment, and then check the avalible OS version? If targetEnvironment has a watchOS target. – 117MasterChief96 Oct 25 '19 at 19:42
  • Not sure I follow. Where/how are you checking the targetEnvironment? – Stephen Oct 25 '19 at 23:09
  • I have not really used this before but I was thinking something like `#if targetEnvironment(watchOS)`. If that is even possible with watchOS, and then inside of that you can check the version for watchOS 5. – 117MasterChief96 Oct 26 '19 at 15:36
  • Sorry this isn't really what I'm asking for. #if targetEnvironment is watchOS, it would need to be running on the watch. I'm looking for a check from iOS – Stephen Oct 27 '19 at 22:36
  • Ok. Sorry I could not help. – 117MasterChief96 Oct 29 '19 at 14:05