有没有办法检测Apple Watch是否与iPhone配对?

sto*_*cis 3 iphone ios apple-watch

我想知道是否有可用的API显示Apple Watch的可用性.我还不想写一个Apple Watch App.在花时间开发手表版本(当然,如果可能的话)之前,我想做一些分析,看看实际用户有多少百分比的Apple Watch.

Bil*_*fas 6

所以在WatchOS 2上这是可能的!

你必须在iPhone方面做:

第一:

import WatchConnectivity
Run Code Online (Sandbox Code Playgroud)

然后 :

   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
        }
    }
Run Code Online (Sandbox Code Playgroud)

我希望它会帮助你:)

  • 从iOS 9.3开始,你必须等待`session(_:activationDidCompleteWith:error:)`才能在委托上调用,然后才能从`session.paired获得可靠的值 (2认同)