How to check whether iPhone and apple watch are connected
Solution 1
So on WatchOS 2 that is possible !
You have to do on iPhone side :
First :
import WatchConnectivity
Then :
if WCSession.isSupported() { // check if the device support to handle an Apple Watch
let session = WCSession.defaultSession()
session.delegate = self
session.activateSession() // activate the session
if session.paired { // Check if the iPhone is paired with the Apple Watch
// Do stuff
}
}
I hope It would help you :)
Solution 2
With watchOS 2.0 you can. To do this you would add these to your ExtensionDelegate if you wanted your Apple Watch to get a notification:
func watchKitSetup() {
if (WCSession.isSupported()) {
let session = WCSession.defaultSession()
session.delegate = self
session.activateSession()
// In your WatchKit extension, the value of this property is true when the paired iPhone is reachable via Bluetooth.
// On iOS, the value is true when the paired Apple Watch is reachable via Bluetooth and the associated Watch app is running in the foreground.
// In all other cases, the value is false.
if session.reachable {
}
}
}
func applicationDidFinishLaunching () {
self.watchKitSetup()
}
// Called when session.reachable value changes, such as when a user wearing an Apple Watch gets out of range of their iPhone.
func sessionReachabilityDidChange(session: WCSession) {
if session.reachable {
}
}
You should also add WCSessionDelegate to your ExtensionDelegate.
Solution 3
From a formal perspective, Apple have not given any indication of how this will be handled.
However, given the pairing and communication area handled by the OS without app involvement, it seems almost certain that any notifications to the user regarding connection issues on the watch (and at the phone end) will be handled by the Watch OS as well. My guess would be that a user will be given an opportunity to resolve the loss of connectivity, or to quit the Watch app if they cannot. From a developer perspective, it is highly likely our apps will not be able to distinguish between an unresolved loss of connectivity and the user quitting an app normally, with the same notification being sent to the Watch Extension for either, but this is only a guess.
It should be noted that there is no third party developer code running on the watch for the current Watch apps, just a UI, so even an unresolved loss of connection will not result in any data loss. If the Watch Extension (which runs on the iPhone) is quit by the OS due to loss of connection to the watch, it will still be able to do its usual data storage and cleanup.
Related videos on Youtube
Mohit Totlani
Updated on July 28, 2020Comments
-
Mohit Totlani almost 4 years
Is there any way to notify user in Apple Watch that the iPhone is now out of range and when it comes back in range. How can we do it in watch extension.
Thanks in advance.
-
GoodSp33d over 9 yearsAs of now there is no notification or delegate which will let you know that phone is out of reach. Just a thought: perhaps you could use openParentApplication and see if you are able to ping iPhone. Just a hunch, have not tried it.
-
-
Mohit Totlani over 9 yearsActually we need to show the alert view when phone goes out of reach. I guess there should be some way.
-
Michael Ochs about 9 years@MohitTotlani no, if the iPhone goes out of range, the watch app will be quit as it can not run without the phone!
-
John Paul Manoza almost 9 yearsIs there any notifications on the watch that will be fired when the connection to the iPhone is suddenly disconnected?
-
BilalReffas almost 9 yearsYes of course ! Then you will see a red cancel phone on your watch:
-
John Paul Manoza almost 9 yearsHow can I observe to that notification within my watchkit extension or watchkit native app?
-
lehn0058 over 8 yearsPaired is not correct, that means you have setup your watch with your phone. You want the reachable property.
-
Chris over 8 yearsThis is such a basic thing, I don't understand why it was left out on WatchOS 1
-
Erik over 8 yearsBut paired returns
false
if the watch app is not in the foreground. What if you just want to know if the watch is connected or not? For example, to determine if notifications will be delivered to the phone or the watch?