2017-03-15 53 views
0

我一直在研究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)' 
    } 
} 
+0

基於你的'init()'的代碼我想知道你是否想要在MCPManager類中的所有這些var聲明......是嗎? – cicerocamargo

+0

是...這個init方法會在創建會話時被調用..你可以找到任何錯誤的原因..預先感謝:) – sudharsan

回答

0

是新來這個framework.Thanks當你說sessionMCPManager編譯器正試圖解決一些MCSessionDelegate funcs中的你正在定義並且不能消除歧義,因爲這些調用是不完整的。然而,好像你正在試圖分配外部範圍中定義的那些變量之一。我想你真正想要的是所有這些瓦爾移動到您MCPManager類的定義,像這樣:

import UIKit 
import MultipeerConnectivity 

class MCPManager: NSObject, MCSessionDelegate { 
    var session : MCSession! 
    var peer : MCPeerID! 
    var browser : MCNearbyServiceBrowser! 
    var advertiser : MCNearbyServiceAdvertiser! 
    var foundPeers = [MCPeerID]() 
    var invitationHandler : ((Bool, MCSession?)->Void)! 

    override init() { 
     super.init() 
     peer = MCPeerID(displayName: UIDevice.current.name) 
     session = MCSession(peer: peer) 
     session.delegate = self 
    } 

    // MCSessionDelegate methods ommited 
} 

這編譯,我希望這是你想要的。

+0

謝謝你soo :) – sudharsan

相關問題