swiftcommunicationapple-watchwcsession

For Apple Watch OS in Swift, how can I have a function run after WCSession activation is complete?


I have a method in my main interface controller class that I wish to run when the WCSession between the phone and watch has finished activating. I know there is a didFinishActivation function in the WCSession class. However, how do I communicate the result of this function to my main interface controller class to run the function in there, after WCSession has finished activating?


Solution

  • You have to make your interface controller class conform to the WCSessionDelegate protocol and then the session(_:activationDidCompleteWith:error:) function will be automatically called once the WCSession is activated.