How to see the javascript errors of PhoneGap app in Xcode?

后端 未结 10 1236
轮回少年
轮回少年 2020-12-04 15:12

I want to debug my PhoneGap app in Xcode, but its Console can not show javascript errors.

10条回答
  •  春和景丽
    2020-12-04 15:54

    Paste the following somewhere near the start of your document so that it gets executed before any of your other JavaScript.

    
    

    And enjoy viewing details of your Javascript errors in the Xcode console window.

    UPDATE: The above technique will log errors such as undefined variables. But syntax errors such as missing commas will still cause the entire script to break without logging anything.

    Therefore you should add the following to the start of your onDeviceReady function:

    console.log('Javascript OK');
    

    If you don't see "JavaScript OK" appearing in your log window when the app launches, then it means you have a syntax error somewhere.

    To save hunting for missing commas, the easiest thing is to paste your code into a Javascript validator such as this one:

    http://www.javascriptlint.com/online_lint.php

    and let it find the error for you.

    Hopefully that takes some of the pain out of debugging.

提交回复
热议问题