Should WCSession.isPaired be true before checking WCSession.isWatchAppInstalled ?

I have a depended watch app bundled with my iOS app.

// ...
<key>WKRunsIndependentlyOfCompanionApp</key>
<false/>
// ...

My code:

guard WCSession.isSupported() else {
  return
}
let session = WCSession.default
session.delegate = self
session.activate()

public func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
  // ... 
  if (session.activationState == .activated) {
     let log = Log(isPaired: session.isPaired, isWatchAppInstalled: session.isWatchAppInstalled)
     uploadLogToServer(log)
  }
  // ...
}

and also:

guard WCSession.isSupported() else {
  return
}
let session = WCSession.default
guard session.activationState == .activated, session.isWatchAppInstalled else {
  return
}
do {
  try session.updateApplicationContext(...)
} catch {
  uploadErrorToServer(error)
}

What I've observed is that when I query the logs in the server's database, I get entities with isPaired = false and isWatchAppInstalled = true. Also, when I query the errors I see deviceNotPaired errors.

So my question is, does Should WCSession.isPaired property be true before accessing WCSession.isWatchAppInstalled property ?

Answered by DTS Engineer in 821551022

The API reference of isWatchAppInstalled says that it is a value indicating whether "the currently paired and active Apple Watch" has installed the app, which, to me, implies that the API assumes the Apple Watch is paired and active, and so to be safe, when I need to check if the watchOS app is installed, I always do session.isPaired && session.isWatchAppInstalled.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

The API reference of isWatchAppInstalled says that it is a value indicating whether "the currently paired and active Apple Watch" has installed the app, which, to me, implies that the API assumes the Apple Watch is paired and active, and so to be safe, when I need to check if the watchOS app is installed, I always do session.isPaired && session.isWatchAppInstalled.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Should WCSession.isPaired be true before checking WCSession.isWatchAppInstalled ?
 
 
Q