官术网_书友最值得收藏!

Debugging workflow

The desktop browser is a great tool for hybrid mobile app development. The majority of your mobile development can be previewed and debugged in your desktop browser. Because PhoneGap leverages open web standards (HTML, CSS, and JavaScript), you can start work in a desktop browser and then move on to a native project once the functionality is fleshed out. This way, it's possible to speed up our development cycles and spend more time implementing core functionality. You can use the latest versions of any of the major desktop browsers such as Internet Explorer (IE), Google Chrome, Firefox, Safari, or Opera to get started with a PhoneGap app. All of these browsers have Developer Tools for logging and debugging your code.

New developers tend to prefer WebKit-based browsers; at the time of writing, Chrome has the largest install base market share followed by Firefox and Internet Explorer.

Note

Chrome also offers a technology known as Google Packaged Apps to build native apps based on web standards. More information about it is available at https://developer.chrome.com/apps/about_apps.

As you have seen, each browser offers different debugging tools and each tool has its pros and cons. Regardless of which tool you use, however, your debugging workflow is the same.

When investigating a specific problem, you will usually follow this process:

  1. Find the relevant code in the debugger's code view pane.
  2. Set breakpoint(s) where you think interesting things may occur.
  3. Run the script again by reloading the page in the browser if it's an inline script, or by clicking on a button if it's an event handler.
  4. Wait until the debugger pauses execution and makes it possible to step through the code.
  5. Investigate the values of variables. For example, look for variables that are undefined when they should contain a value, or return false when you expect them to return true.

If necessary, you can use the console to evaluate code or change variables for testing. You can also execute complex JavaScript code and test a solution before implementing it.

Identifying the problem by learning which piece of code or input caused the error conditions and isolating it is a suitable approach. However, with mobile apps, things are not always so straightforward. The advantage of PhoneGap is that you can develop and debug in a common environment such as the browser, but keep in mind that a mobile app has to be tested and debugged on the target devices as well.

Although it's not a neat way of debugging, you can use console log messages to debug. These log messages will be printed in the console of the browser development tool. A sample use of the JavaScript code is provided here for reference:

console.log("Application running now");

There are several other debugging tools for PhoneGap/Cordova. While a few of them are free services, some of them are paid services:

  1. Ripple Emulator: http://emulate.phonegap.com/
  2. GapDebug: https://www.genuitec.com/products/gapdebug/
  3. jsHybugger: https://www.jshybugger.com/
  4. Weinre: http://people.apache.org/~pmuellr/weinre-docs/latest/
  5. Adobe Edge Inspect: https://creative.adobe.com/products/inspect
  6. Chrome: https://developer.chrome.com/devtools/docs/remote-debugging
主站蜘蛛池模板: 株洲市| 吴川市| 昌吉市| 永吉县| 辽阳县| 六安市| 樟树市| 郓城县| 年辖:市辖区| 芮城县| 酉阳| 大新县| 汉川市| 巧家县| 钦州市| 汉中市| 常德市| 灌云县| 景洪市| 金门县| 长治县| 竹北市| 江口县| 明水县| 蓝田县| 博白县| 宁德市| 合江县| 敦化市| 麻栗坡县| 无锡市| 西平县| 大同市| 项城市| 广灵县| 崇义县| 南岸区| 乃东县| 塔河县| 万盛区| 桐梓县|