Sending time from Apple Watch to Phone is not returning the correct number

Viewed 29

When I send data from a timer on the Apple Watch, it keeps sending 1 instead of sending the actual number in "message": timerCount. How can I ensure the right number is being sent back to the phone, instead of 1. I am not sure where it is pulling the 1 from. When I print timerCount, it returns the same number as on the timer.

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))
}
0 Answers
Related