ShogoSaito
ShogoSaito

Reputation: 51

(Watch Connectivity) WCSession is missing its delegate (only in XCode11.0)

As a title, I found this error only in XCode11.0.
I send some data from app (written with react-native) to appleWatch.
I'm using now watch-connectivity and the method of 'updateApplicationContext' for communicating iPhone with it.
But appleWatch returned the following error.

The error log is below:

(1) [WC] WCSession is missing its delegate
(2) [WC] -[WCSession handleApplicationContextWithPairingID:]
_block_invoke delegate (null) does not implement session:didReceiveApplicationContext:

The source code is below:

let session = WCSession.default
  override func awake(withContext context: Any?) {
    super.awake(withContext: context)
    session.delegate = self
    session.activate()
  }

func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
    //
  }

And I found error(1) is not happened in XCode10.3.
... error(2) is also happened.
Do you have any idea regarding this error(1) or (2)?
I guess this is caused by XCode11.0, but I couldn't locate what causes this.

Thanks.

Upvotes: 4

Views: 1980

Answers (1)

ShogoSaito
ShogoSaito

Reputation: 51

I fixed these errors.
In fact, I implemented the following:

override func awake(withContext context: Any?) {
    super.awake(withContext: context)
    if WCSession.isSupported() {
      let session = WCSession.default
      session.delegate = self
      session.activate()
      if session.isReachable {
        print("your iphone is Reachable")
      } else {
        print("your iphone is not Reachable...")
      }
    } else {
      print("This device is not supported.")
    }

    let aList = dataAccess.fetchData(id: nil)
    let aControllers = [String](repeating: "aController", count: aList.count)
    MainInterfaceController.reloadRootControllers(withNames: aControllers, contexts: aList)
  }

I found that the last row causes this errors.
I guess the method of 'reloadRootControllers' resets WCsession, even if it is already activated.
So, I set session which is for receivedApplicationContext, but event is not happened and called as if 'delegate (null) does not implement session'.

Upvotes: 1

Related Questions