如何修复 [WC] 因缺少委托 Swift 而拒绝激活的问题



嗨,我有这个功能

extension UIViewController: WCSessionDelegate {
public func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {        
}
public func sessionDidBecomeInactive(_ session: WCSession) {
}
public func sessionDidDeactivate(_ session: WCSession) {
}

//MARK: -SYNC DATA TO APPLE WATCH
func syncToAppleWatch(){
var session: WCSession?
if WCSession.isSupported() {//4.1
session?.delegate = self
session = WCSession.default//4.2
session?.activate()//4.4
}

}

我在DidLoad中称为"syncToAppleWatch"。但是我收到此错误

[WC] denying activation due to missing delegate
[WC] WCSession has not been activated

我该如何解决它?

这两行毫无意义

session?.delegate = self  // session is still nil here, delegate won't be set
session = WCSession.default

将顺序更改为

session = WCSession.default
session?.delegate = self 

相关内容

  • 没有找到相关文章

最新更新