我一直在研究multipeer連接framework.While初始化一個會話對象,我得到一個錯誤,指出「模糊引用到成員'會話(_:peer:didChange)'「。我得到相同的錯誤,同時使類作爲同一個會話對象的委託。這裏是代碼implementation.Any建議將幫助我提前:)在xcode 8 multipeer連接框架中對成員會話(_:peer:didChange)的錯誤引用swift 3
#import UIKit
import MultipeerConnectivity
var session : MCSession!
var peer : MCPeerID!
var browser : MCNearbyServiceBrowser!
var advertiser : MCNearbyServiceAdvertiser!
var foundPeers = [MCPeerID]()
var invitationHandler : ((Bool, MCSession?)->Void)!
class MCPManager: NSObject,MCSessionDelegate
{
public func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState)
{
return
}
public func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID)
{
return
}
public func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID)
{
return
}
public func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress)
{
return
}
public func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL, withError error: Error?)
{
return
}
override init()
{
super.init()
peer = MCPeerID(displayName: UIDevice.current.name)
session = MCSession(peer: peer) // Ambiguous reference to member 'session(_:peer:didChange)'
session.delegate = self //Ambiguous reference to member 'session(_:peer:didChange)'
}
}
基於你的'init()'的代碼我想知道你是否想要在MCPManager類中的所有這些var聲明......是嗎? – cicerocamargo
是...這個init方法會在創建會話時被調用..你可以找到任何錯誤的原因..預先感謝:) – sudharsan