I’m attempting to call a nested function within my hype code from my swift app but it isn’t working (please see the error at the end of the post). Any ideas?
Swift code
var js = "runTimer(44);"
webView.evaluateJavaScript(js)
Javascript
function clock(hypeDocument, element, event) {
function runTimer(numStart) {
baseSec = 0;
baseMin = 0;
baseStd = 0;
firstStart = 1;
setTime();
var idVar = setInterval(setTime, 1000);
function setTime() {
var now = new Date();
var hour = now.getHours();
if (hour > 12) hour -= 12;
var stundenzeiger = document.getElementById('stunde');
if (hour === 0 && minute === 0 && second === 0) baseStd += 360;
var Winkel = baseStd + (hour * 30 + (minute * 6 / 12));
if(numStart > 0){
rotate(stundenzeiger, Winkel);
}
numStart = numStart - 1;
hypeDocument.getElementById('displayNumber').innerHTML = numStart;
if (numStart < 1) {
clearInterval(idVar);
}
var zehntelSekundenzeiger = document.getElementById('zehntel');
console.log(numStart)
if (firstStart) zehntelSekundenzeiger.classList.add("zehntel");
firstStart = !1;
}
function rotate(el, winkel) {
el.style.webkitTransform = 'rotate(' + winkel + 'deg)';
el.style.mozTransform = 'rotate(' + winkel + 'deg)';
el.style.transform = 'rotate(' + winkel + 'deg)';
}
}
XCode Error
Optional(Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=ReferenceError: Can't find variable: clock, WKJavaScriptExceptionColumnNumber=6, WKJavaScriptExceptionSourceURL=file:///private/var/containers/Bundle/Application/D741AFC0-1BB7-41C0-A029-ED57820CDDEC/Web%20Theatre.app/, NSLocalizedDescription=A JavaScript exception occurred})
}