0

I have made an application for iOS device to get the heart rate data continuously from the watch. It is working as intended and I wanted to add a test case checking if the watch is connected (paired) with the device. My code for testing it is:

if WCSession.isSupported() {
    let wcsession = WCSession.default
    wcsession.delegate = self as? WCSessionDelegate
    wcsession.activate()
    if(wcsession.isPaired){
        print("paired")
    }else{
        print("not paired")
    }
}

However, I get an error:

2020-02-29 15:25:55.044843+0900 HeartRateApp[68975:11196372] [WC] denying activation due to missing delegate 2020-02-29 15:25:55.044969+0900 HeartRateApp[68975:11196372] [WC] WCSession has not been activated

even though everything is working and I receive the data from the watch successfully...

I have looked at other questions here but they all have similar solutions:

Solution 1

Solution 2

denistepp
  • 489
  • 7
  • 23

1 Answers1

0

Problably self as? WCSessionDelegate returns nil because the class doesn't implement the WCSessionDelegate protocol. The cast as? WCSessionDelegate should not be necessary. You need to make your class conform to the protocol (as seen in Solution 2):

class SomeClass: WCSessionDelegate {

    // ...

}
Ralf Ebert
  • 3,556
  • 3
  • 29
  • 43