10-12-2017 15:24 - edited 10-13-2017 19:39
10-12-2017 15:24 - edited 10-13-2017 19:39
I am developing a watch face that connects to an API and retrieve tide info for the location of the phone. It is mainly for me, but I will be happy to make it available on the store.
I am having issues with a couple of things, and I would like to solve them before moving ahead with the development of it. Basically the it has a delay that happens at first run from studio, and every time I launch an app and go back to the watch face.
1. The clock takes a second or two before displaying time.
2. Tides takes a few seconds before being displayed.
3. When developing using console.log to check messages and var, the first time it runs well and display values. Then I have to run it few times before console.log shows something. It seemed to have improved once I changed the package.json to watchface, but I was wondering if the behavious is normal or code related.
Answered! Go to the Best Answer.
10-13-2017 10:51
10-13-2017 10:51
Hey,
Don't nest the event handler inside your updateClock method.
You only subscribe to the tick event once, and update is called each time the tick event is emitted.
function updateClock(evt) {
myDate.innerText = (evt.date.toString().slice(0,4)) + (evt.date.toString().slice(8,10));
var hours = evt.date.getHours() > 12 ? evt.date.getHours() - 12 : evt.date.getHours();
hours = hours < 10 ? "0" + hours : hours;
var minutes = ("0" + evt.date.getMinutes()).slice(-2);
myTime.innerText = hours + ":" + minutes; };
clock.ontick = function(evt) {
updateClock(evt)
};
10-13-2017 10:51
10-13-2017 10:51
Hey,
Don't nest the event handler inside your updateClock method.
You only subscribe to the tick event once, and update is called each time the tick event is emitted.
function updateClock(evt) {
myDate.innerText = (evt.date.toString().slice(0,4)) + (evt.date.toString().slice(8,10));
var hours = evt.date.getHours() > 12 ? evt.date.getHours() - 12 : evt.date.getHours();
hours = hours < 10 ? "0" + hours : hours;
var minutes = ("0" + evt.date.getMinutes()).slice(-2);
myTime.innerText = hours + ":" + minutes; };
clock.ontick = function(evt) {
updateClock(evt)
};