[SOLVED] Script does not execute on iOS 9

Hey, does anyone have an idea why a script wouldn’t work on ios9 but works on desktop browser?

Hi @Anton_Gunaratnam_s_S! What kind of script it is?

It’s added to a script component.

Hi @Anton_Gunaratnam_s_S

There are many reasons why some javascript code may execute in some environments but not others. It comes down to compatibility issues on how browsers implement different JavaScript APIs. You can check out some information on what browsers implement what functionality here on MDN

Without more information about exactly what code is inside your script, it’s impossible to definitively say exactly what the issue is.

If your script contains an API call that is not supported by safari on IOS, it may cause a runtime error that causes the whole script to stop working on safari on IOS.

1 Like

I’ve set up a public project here:

https://playcanvas.com/project/860340/overview/script-not-running-on-ios9

The cloth.js seems to not work on ios9 because the alert message in the first line of the initiate function does not execute on ios9 but it works fine on the desktop that I am coding it in.

It works correctly on iOS 15. There is probably only a problem using alert() on iOS 9. Did the other parts of the script work as expected?

Are you perhaps running a web view in an iOS app rather than using Safari? If so, you need to implement the web view UIDelegate callbacks to render the alerts natively.

I’ve added the below 3 lines of code in the init and update function of cloth.js to see if the entity moves, but it does not execute this on ios9:

alert(‘Why is THIS MESSAGE NoT executed ON ios9’);
this.entity.root.findByName(“Grid”).setPosition(1000,1000,1000);
return;

I’m using Safari on ios9

You may see the code, I’ve made it public so anyone can look inside of it.

I guess this line is not correct. I suggest to try one of the lines below.

this.app.root.findByName("Grid").setPosition(1000,1000,1000);
this.entity.findByName("Grid").setPosition(1000,1000,1000);
1 Like

Does this also not work on iOS9? Are there Safari settings that might block javascript pop ups like alert?

changing ‘let’ to ‘var’ in the for loops, and changing this.entity.root.findByName(“Grid”) TO this.app.root.findByName(“Grid”)
FIXED the problem, it works now on ios9

2 Likes