简体   繁体   English

类型“AppDelegate”不符合协议“WCSessionDelegate”调用无限次

[英]Type 'AppDelegate' does not conform to protocol 'WCSessionDelegate' calls infinity times

I wan't to pair iphone application with AppleWatch , when i'm implement to AppDelegate a WCSession delegate , they always show to me error "Type 'AppDelegate' does not conform to protocol 'WCSessionDelegate'" But i'm added the function of this protocol Here i'm implement code of protocol我不想将 iphone 应用程序与 AppleWatch 配对,当我实现 AppDelegate WCSession 委托时,它们总是向我显示错误“类型‘AppDelegate’不符合协议‘WCSessionDelegate’”但我添加了这个协议我在这里实现了协议的代码

if WCSession.isSupported() {
            let wcsession = WCSession.default
            wcsession.delegate = self
            wcsession.activate()
        }

enter image description here在此处输入图片说明

Below the AppDelegate class add this extension that confirm to the delegate protocol and use it subsAppDelegate类下面添加这个扩展,确认委托协议并使用它 subs

extension AppDelegate: WCSessionDelegate { 
//use WCSessionDelegate functions
} 

Add below methods for WCSessionDelegateWCSessionDelegate添加以下方法

func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {

}

func sessionDidBecomeInactive(_ session: WCSession) {

}

func sessionDidDeactivate(_ session: WCSession) {

}

This are required methods for WCSessionDelegate这是WCSessionDelegate所需的方法

And just clean and rebuild your project.只需清理并重建您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM