0
的一部分我已經創建的對象與多個屬性來發送:1串(SESSIONDATE),另一個對象的陣列,1個時間間隔和1個INT(sessiondistance)。我使用多重連接發送此對象,並且設備註冊它們正在接收數據。但是,整數不被接收。它在接收設備上變爲零。IOS Multipeer連通性 - 僅發送我的對象
感謝您的幫助!
FUNC會話(_會話:MCSession,對等體的peerID:MCPeerID,didChange狀態:MCSessionState){ 開關狀態{ 情況MCSessionState.connected: 打印( 「連接:(peerID.displayName)」 )
joinedSession = true
let hosting = ViewController().hostCheck()
print("InMCSessionConnected")
if(hosting == false){
}
if(hosting == true){
if(self.ConnectedUsers.text?.range(of: peerID.displayName) == nil){
DispatchQueue.main.async {
self.ConnectedUsers.text?.append(peerID.displayName + ", ")
}
}
HostingSession.noJoined = HostingSession.noJoined + 1;
print(HostingSession.noJoined)
print(SessionsManager.SessionInception.last?.SessionDistance)
print(SessionsManager.SessionInception.last?.SessionDate)
print("SendingData")
sendData(SessionsManager.SessionInception.last!)
print("SendingData")
}
case MCSessionState.connecting:
print("Connecting: \(peerID.displayName)")
case MCSessionState.notConnected:
print("Not Connected: \(peerID.displayName)")
joinedSession = false
}
}
func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
//This is called when data arrives
print("Starting Received Data")
let hosting = ViewController().hostCheck()
if(hosting == false){
let SessionSent = (NSKeyedUnarchiver.unarchiveObject(with: data) as! Sessions)
print(SessionSent.SessionDistance)
SessionsManager.SessionInception.append(SessionSent)//appends the session sent
//2 method gets the current date and line below appends this date to title
let currentSession = SessionsManager.SessionInception.last
let currentSessionDate = (currentSession?.SessionDate)!
print(currentSessionDate)
reloadView()
//Creates the table
TableView.rowHeight = 90
TableView.delegate = self
TableView.dataSource = self
TableView.reloadData()
print("Finished Received Data")
//ReadyButton.enabled = true
}
}
請發表您的代碼作爲文本 – Prisoner