Been trying to get to the bottom of this for a couple of days now. For some reasons the mozMobileMessage
function doesn't seem to work properly with setIntervals (using the script on KaiOS 2.5 app). The code below (where the mobile number is captured as part of the app) only ever sends a single SMS message to the phone. Any idea how to fix this? I'd like the message to be sent at set intervals for a set duration:
let timerId = setInterval(navigator.mozMobileMessage.send(mobileNumberInput.value, "Hello"), 10000);
setTimeout(() => {clearInterval(timerId);}, 40000);
I've tried to call mozMobileMessage
several times separately within the code as per below to check if this could be to do with some function limitations. But calling the function manually within the code will work fine and sends an SMS as many times as the functions is called:
navigator.mozMobileMessage.send(mobileNumberInput.value, "Hello");
navigator.mozMobileMessage.send(mobileNumberInput.value, "Hello");
navigator.mozMobileMessage.send(mobileNumberInput.value, "Hello");
You are passing invalidate parameters to
setInterval
function.By shorthand, you can to use this syntax for both
setInterval
andsetTimeout
Explanation
First parameter is a function name, you don't have to call it initially timers will do for you.
Second parameter is delay obviously in seconds.
Finally remaining passed
parameters
are be thearguments
for your function that passed in firstparameter
.Let says for example, I have the following function
In your case it will be like