出於某種原因,因爲我更新我碰到下面的錯誤與MultiPeer connectivty工作時,我似乎無法弄清楚:爲什麼這個swift代碼錯了?
「類型MessageServiceManager不符合協議MCSession」
一切都過去完美,但現在出於某種原因,一切都破裂了,我不知道爲什麼。 這是它讓所有調動起來代碼:
extension MessageServiceManager : MCSessionDelegate {
func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
NSLog("%@", "peer \(peerID) didChangeState: \(state.stringValue())")
self.delegate?.connectedDevicesChanged(self, connectedDevices: session.connectedPeers.map({$0.displayName}))
}
func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
NSLog("%@", "didReceiveData: \(data)")
let str = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String
self.delegate?.messageChanged(self, messageString: str)
}
func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {
NSLog("%@", "didReceiveStream")
}
func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL??, withError error: Error?) {
NSLog("%@", "didFinishReceivingResourceWithName")
}
func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
NSLog("%@", "didStartReceivingResourceWithName")
}
}
好吧,錯誤消息告訴你所有你需要知道的:你的類不符合'MCSessionDelegate' - 要麼使用自動完成,要麼手動檢查'MessageServiceManager'從協議中錯過了什麼 –
沒有錯過那個問題 – SemAllush