当我从Apple Watch上的计时器发送数据时,它会继续发送1而不是在"message": timerCount
中发送实际数字。如何确保将正确的号码发送回手机,而不是1.我不知道它从哪里拉出1。当我打印timerCount
时,它返回与计时器相同的数字。
let myInterval: TimeInterval = 0.0
var timerCount: Int = 0
var timer = Timer()
func stopPlay() {
let startTime = Date.timeIntervalSinceReferenceDate
print(timerCount) //this prints the actual time
let data: Dictionary<String, AnyObject> = [ "startTime": startTime as AnyObject, "message": timerCount as AnyObject]
if session.isReachable {
session.sendMessage(data, replyHandler: nil, errorHandler: nil)
} else {
let action1 = WKAlertAction(title: "OK", style: .default, handler: stopPlay)
presentAlert(withTitle: "Workout Complete", message: "Connect to your iPhone", preferredStyle: .actionSheet, actions: [action1])
}
}
@IBAction func start_button() {
if isStarted == false {
self.timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.update), userInfo: nil, repeats: true)
self.startStopButton.setTitle("Stop")
isStarted = true
} else if isStarted == true {
self.timer.invalidate()
self.startStopButton.setTitle("Resume")
isStarted = false
}
}
func update() {
internalDuration -= 1
totalTimeCounter += 1
timerCount += 1
self.elapsedLabel.setText(timeString(time: totalTimeCounter))
}