Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether iPhone and apple watch are connected

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.

like image 312
Mohit Totlani Avatar asked Jan 06 '15 06:01

Mohit Totlani


People also ask

How do I make sure my phone is connected to my Apple Watch?

If your Apple Watch isn't pairing with your iPhone, there are a number of ways you can fix the connection. First, make sure both devices have Wi-Fi and Bluetooth enabled and are in range of each other. Then, try restarting your Apple Watch and iPhone, as well as resetting your iPhone's network settings.

How do I check connection on Apple Watch?

Check the connection between your iPhone and Apple WatchTap the iPhone icon in Control Center. If your devices are connected, your iPhone should make a "ping" sound.

Why is my Apple Watch disconnected from iPhone?

Keep your Apple Watch and paired iPhone close together to make sure that they're in range. On your iPhone, make sure that Airplane Mode is off and that Wi-Fi and Bluetooth are on. To check, open Control Center. If you see the Airplane Mode icon on your watch face, Airplane Mode is on.


3 Answers

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 :)

like image 188
BilalReffas Avatar answered Oct 18 '22 09:10

BilalReffas


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.

like image 31
lehn0058 Avatar answered Oct 18 '22 07:10

lehn0058


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.

like image 22
Duncan Babbage Avatar answered Oct 18 '22 08:10

Duncan Babbage