在我的下面的代码中,我试图将时间作为字符串发送到多个对等体,但是从不发送字符串或者我的函数永远不会在对等端运行。这是我的代码,没有错误
@IBAction func pick(sender: AnyObject) {
self.presentPicker(sender)
let now = NSDate()
let nowData = NSKeyedArchiver.archivedDataWithRootObject(now)
var error : NSError?
self.session.sendData(nowData, toPeers: self.session.connectedPeers, withMode: MCSessionSendDataMode.Unreliable, error: &error)
println("sending data")
/* let formatter = NSDateFormatter()
//formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) // you can set GMT time
formatter.timeZone = NSTimeZone.localTimeZone() // or as local time
formatter.dateFormat = "HH:mm:ss:SSS"
formatter.dateFormat = "HHmmssSSS"
*/
if error != nil {
print(":( Were sorry there was an error :( please notify/email the developers (mecnewport@gmail.com) about this error: \(error?.localizedDescription)")
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var DestView: ViewController = segue.destinationViewController as! ViewController
DestView.selectedSong = MPMediaItemCollection()
}
// self.updateChat(self.messageField.text, fromPeer: self.peerID)
// self.startTime.text = ""
}
断裂
func session(session: MCSession!, didReceiveData data: NSData!,
fromPeer peerID: MCPeerID!) {
dispatch_async(dispatch_get_main_queue()) {
var nowData = NSString(data: data, encoding: NSUTF8StringEncoding)
// if time_value = startTime
let formatter = NSDateFormatter()
//formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) // you can set GMT time
formatter.timeZone = NSTimeZone.localTimeZone() // or as local time
formatter.dateFormat = "HH:mm:ss.SSS"
var currentTime = formatter.stringFromDate(NSDate())
println(currentTime)
//"var Time.delegate"
var startTime = (nowData as NSString?)!.integerValue + 100
println(startTime)
}
}
}