对于Swift中的Apple Watch OS,如何在WCSession激活完成后运行函数?

时间:2022-08-01 03:37:25

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?

我的主界面控制器类中有一个方法,我希望在手机和手表之间的WCSession完成激活后运行。我知道WCSession类中有一个didFinishActivation函数。但是,在WCSession完成激活后,如何将此函数的结果传递给我的主接口控制器类以在其中运行该函数?

1 个解决方案

#1


1  

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.

您必须使您的接口控制器类符合WCSessionDelegate协议,然后在激活WCSession后将自动调用会话(_:activationDidCompleteWith:error :)函数。

#1


1  

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.

您必须使您的接口控制器类符合WCSessionDelegate协议,然后在激活WCSession后将自动调用会话(_:activationDidCompleteWith:error :)函数。