0

In my app, I want to implement functionality like when iPhone away with some distance from iWatch than watch app show local notification with a text message

Ashish
  • 2,977
  • 1
  • 14
  • 32
  • I've wanted to write an app like this for the watch for a while but as far as I can tell this is not possible. You would have to always have your app running and monitoring the connection between the phone and watch. – beyerss May 31 '17 at 11:38

1 Answers1

1

If it is enough for you to get notified when the Watch gets disconnected from the Phone, you could use the WatchConnectivity framework to achieve this. The optional func sessionReachabilityDidChange(_:) gets called on the Watch when it disconnects from the Phone. However, your WatchExtension needs to be running in the foreground or with high priority in the background for this function to work.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • I want to show notification base on iPhone distance with watch. It's help user if they forget their device – Ashish May 31 '17 at 12:39
  • Well for that scenario it should be enough to notify the user when the Watch disconnects from the Phone, since in most cases when this happens, the user can still grab their Phone if they forgot about it. To actually measure the distance between the devices you could try to send messages between the Phone and the Watch using the CoreBluetooth framework and estimate the distance based on signal strength (as in [this question](https://stackoverflow.com/questions/13705647/finding-distance-from-rssi-value-of-bluetooth-low-energy-enabled-device)), but I am not sure if you can use CB with the Watch – Dávid Pásztor May 31 '17 at 12:45
  • sessionReachabilityDidChange(_:) not called when watch disconnected with device – Ashish Jun 01 '17 at 10:15
  • If the app is running, it should be called as stated in the official documentation of the feature. – Dávid Pásztor Jun 01 '17 at 10:17
  • Yes, sessionReachabilityDidChange(_:) it's called only when watch app is active but not called when app in background – Ashish Jun 01 '17 at 10:28
  • I have stated this in my answer as well :) Actually it is called in the background if your app is running with high priority (i.e. workout or complication refresh). Again, have a look at the [official documentation](https://developer.apple.com/reference/watchconnectivity/wcsession/1615683-isreachable) for more details. – Dávid Pásztor Jun 01 '17 at 10:37