Saturday, May 10, 2014

An Overview of Mobile Debugging Techniques – Part One

An Overview of Mobile Debugging Techniques – Part One

12.10.2013
| 9372 views |
The Mobile Zone is presented by New Relic and Verivo. New Relic is a performance monitoring tool and has a Data Nerd T-Shirt with your name on it if you sign up. Verivo is an enterprise mobile app platform designed to radically simplify the complexities of building, securing and controlling custom enterprise apps.
Working with mobile sites (or hybrid applications via PhoneGap) can be painful at times when you need to debug. Unless you're perfect (and therefore, do not exist, so how are you reading this?), you're going to need to iterate through numerous different builds of your application before you get it just right. In this article, I'm going to look at a few of the options available to developers to help debug their mobile web applications.

An Overview of Mobile Debugging Techniques – PartTwo

Safari Remote Debugging

The first option we'll look at is specific to iOS devices, but can still be useful for debugging in general. In iOS6, Apple introduced a new feature called Safari Remote Debugging. This allows you to use the Safari web browser to debug web applications being run on iOS devices (both iPhones and iPads). This also includes PhoneGap applications. Unfortunately, this option is only available to folks running Mac OS X.
To use this feature, your iOS device must be physically connected to your laptop. Next, you need to enable it (one time) on the device itself. Open the Settings app, go to Safari, and then click the Advanced Menu. Here is a screenshot from an iOS7 device:

Simply enable Web Inspector and this device will be ready for remote debugging. Before continuing on, open up Safari on your device and visit any web page.
Next, open up Safari. If you don't see the Develop menu, go into your Safari preferences, select the Advanced tab, and turn it on there.

In the Develop menu you will see a new menu option that matches the name of your iOS device. (Note that if you have multiple devices connected you will see all of them, including the iOS Simulator if you have that running.)

If you mouse over the device name, you'll see the name of the web page visible in Safari, or a list of URLs if you have multiple tabs opened.

Select the URL and Safari will open up a set of dev tools:
You now have the ability to interact with your mobile Safari directly from the desktop. If you're primarily a Chrome user, the menu options here may not be terribly obvious. (The next version of Safari will be updating the developer tools UI so what you have now may be a bit different.)
Going from left to right, the menu icons are:
  • Resources: This provides roughly the same view as the Elements panel in Chrome's Dev Tools.
  • Storage: This is similar to the Resources panel in Chrome's Dev Tools. Note that unlike Chrome's Dev Tools, the Web Inspector only seems to support cookies and Web SQL databases. Local Storage is missing from the UI. (Although you could use the console to inspect these values.)
  • Instrument: This includes network requests as well as timing data for layout and JavaScript events. This corresponds roughly to the Network, Timeline, and Profiles panel in Chrome.
  • Search: Allows you to search across all the data in the current request - this includes HTML, JavaScript, and CSS source.
  • Issue: Reports on issues found in the current request. You can find similar information in Chrome's Console, but this focused view is pretty handy.
  • Debug: Safari's JavaScript debugger.
  • Breakpoint: Where you set and view breakpoints.
  • Finally, the Console.

Let's take a closer look at the tabs that I think are going to be the most valuable to you in terms of debugging. To be clear, you should be aware of the capabilities in all the different tabs, but for this article we will focus on some of the more important ones.

The Console

The Console tab is hopefully familiar to you already. On the desktop this is where you can find errors and run arbitrary code. This is even more useful for mobile websites. In the screenshot below you can see the console reporting a simple JavaScript error.
As I mentioned above, you can also run code from here as well. This could be useful for manually firing functions or even just checking variables.
Here's a simple example. I've used the console to check the value of navigator.userAgent and run an alert. Notice that it fires on the device (the simulator in this case) itself.


Resources

The Resources tab gives you access to the DOM. As you select code in the panel, you will see it highlighted in real time on the device.

Even more interesting is that you can edit the HTML live on the device. Double clicking on the text of the h1 tag lets us edit and modify it.


Selecting the icons on the upper right hand side give you access to the tag node and style properties. Under the style property menu you can actually modify the design. This is especially helpful on mobile devices. In the example below I've just added a color, but you could play with margins, padding, and size values to try to improve the design of your web site.


Instrument

In the Instrument panel, the network requests are probably the first useful tool you will need. In complex Ajax-based applications, being able to trace and monitor network requests is incredibly helpful.
The first thing you should be aware of though is that network requests that fail.  404s for example, will not show up here. Instead they will show up in the console only. Chrome on the Desktop will show the failed network requests in both the Networks tab and the console.
Let's look at a simple example. I've run a simple Ajax request. Notice how it shows up in the Network panel along with other requests (CSS, JavaScript, etc).


Notice the arrow on the selected row? Clicking it will load the raw result of the request:


Be sure to check the rest of the Instrument panel as the rendering section and JavaScript events could also be incredibly helpful.

The Debugger

The final feature we'll look at is the debugger. This involves a few different aspects of the web inspector. First, in the Resource panel I can select a JavaScript file from my application:
I can then simply click a line to add a breakpoint. I've done so on line 7 below:
Now when I execute this on the device, it will actually pause execution and let you step through the function one step at a time.

Chrome Remote Debugging

For the next portion of this article, we'll focus on Chrome Remote Debugging. As you can probably guess, this is focused on Android devices and the Chrome browser. It is important that you remember that there is a difference between the stock Android browser and Chrome for Android. The debugging supported by Chrome on the desktop is for Chrome on the device. That's probably obvious but don't forget. As of a report from approximately 6 months ago, the stock Android browser was in use around 10 times more than Chrome for Android! Despite that, you can still make use of Chrome Remote debugging.

To begin, you install the ADB extension for Chrome (https://chrome.google.com/webstore/detail/dpngiggdglpdnjdoaefidgiigpemgage). This extension adds a new icon to the upper right hand corner of your Chrome browser:

In this case, I've got an Android device connected already. (Note - unlike the iOS remote debugger, you can't use this feature with the Android emulator.) Clicking on it exposes these options:

Startand Stop ADB refer to the debugging service and as long as it is already started you can just leave it be. View Inspection Targets gives you a list of all connected devices.

Next, on your Android device, open up Chrome, go to Settings, then Advanced, Developer tools, and enable USB Web debugging.

Once you've done that, return to your desktop, select View Inspection Targets, and note how the Desktop Chrome can tell what site you have open on the device. In fact, if you have multiple sites open in different tabs, you can see a list of them on your desktop:
You can see a few options for each tab. Reload and Close do exactly what you would imagine. The interesting option here is Inspect. Clicking Inspect opens a new window with the familiar Chrome Dev Tools UI:
(Blockquote - What is the SchemaDump tab you ask? That's actually an extension I wrote myself. Chrome lets you write extensions that do many things, including extend the built in developer tools. The same extensions that work for my desktop will work for Android as well!)

We won't go over the tabs as the assumption is that most folks are pretty familiar with Chrome already. If not, you can check out this freeDevTools course on CodeSchool.  As you can imagine, the console is connected to the device. Running a command on the desktop will execute on the mobile device.

Also, much like the Safari debugger, you can select DOM items in the Elements panel and see them update live on the device. You can also modify these elements to test out CSS modifications and other changes. (Pardon the lame camera picture but there was no way to select both the device DOM being highlighted and the desktop!)

As you can imagine, Chrome's developer tools are very powerful and familiar to most developers. Having these available to you for testing mobile devices will be incredibly useful!

What's Next?

In this article we focused on the "big boys", iOS and Chrome remote debugging. Certainly there are other mobile platforms out there and other tools available to you. In the next article, we'll discuss two more tools, Adobe's Edge Inspect and Weinre.

An Overview of Mobile Debugging Techniques – PartTwo

This article was commissioned by Intel and the Tizen Mobile Web Development team.

Source: 
http://css.dzone.com/articles/overview-mobile-debugging 

Tuesday, May 6, 2014

手機應用程式開發

圖片來源:Getty Images
今時今日,手機不離身,是現代人的寫照。看影片新聞、聽音樂、玩遊戲、修圖、和朋友聊天,甚至找路看地圖、查字典、買戲票等等,只要一部智能手機,下載一堆應用程式(Apps),全部就能做到。不能否認,我們的生活與Apps已密不可分。若你遇到難題時,腦海經常閃過用Apps能夠解決就好的念頭,你已經具備成為手機程式開發員(Apps Developers)的基本條件了。
手機應用程式開發公司Mtel行政總裁黃明威(Willy),曾為機管局、機鐵、電影院線等製作Apps。他認為,手機程式開發員需要具備基本電腦製作程式的智識外,更重要是要有對Apps的熱愛:「要常常從生活出發,了解自己所需之餘,同時了解世界需要甚麼,將這些想法透過Apps,在生活中實踐出來。要做到這一點,需要熱愛Apps,首先你自己要想用,然後更想推薦予身邊的朋友,以至客戶,才有機會成為一個成功的手機程式開發員。」


 







與潮流鬥快 

Willy笑言,要隨著時代走,更要比時代走得更快、更前,才能夠成功。
開發員除了接受客戶要求,亦要不時向公司作出建議,製作新的手機應用程式。所以,開發員一定要對生活有敏銳觸覺,以及天馬行空的想法。「舉個例說,有同事看到通訊軟件以及網上交友平台,興起用電影、電視截圖代替文字作回覆,引發我們開發一個App,用戶可以將截圖上載及下載轉發,成為截圖圖庫。關鍵在於你要夠快、夠獨特,就有製作一個出色App的條件。」 
Apps下載的市場是全球性的,所以製作Apps的要求及客戶亦來自全球,發展潛力可想而知。在港澳台均設有辦公室的Willy強調,手機應用程式只是其中一個電子訊息傳播的渠道,隨時會改變。手機應用程式大約2008年才出現,之前其公司的程式設計員經歷過Java GamesWallpaper Download,甚至手機鈴聲Download的年代。「要隨著時代走,更要比時代走得更快、更前,才能夠成功。」
要追上社會脈搏,更加要追上手機的變化速度,所製作的Apps要跟得上步伐,手機軟件便要不停更新,令其可以運用到最新的科技,所以手機程式開發員在產品完成前後,亦要日以繼夜不停地作出修改,工時無可避免較一般辦公室工作長,要有心理準備加班是家常便飯。打算入這行,一般而言,由初級手機程式開發員做起,起薪點大約為$13,000。經過23年時間累積經驗,便可晉升為高級手機程式開發員,月薪普遍由$20,000起跳。

進修課程豐儉由人

若然有志投身這一行,卻對電腦程式編寫不太熟識,坊間有不少機構提供進修機會,並以短期課程為主,內容包括相關程式編寫以至介面設計等;學費亦豐儉由人,由一千多元至一萬多元不等,視乎課程內容及教學時數而定。 其實,現時有不少自製Apps的網頁,只需按步驟輸入資料,就能製造出一個App,而且大部分是免費的。想知道自己對這方面是否有天分和興趣,不妨瀏覽一下這類網頁,動腦動手做做看,也是不錯的測試方法。

手機程式開發員的晉升階梯
職位
月薪()
初級手機程式開發員 (0-3年經驗)
$13,000-$15,000
高級手機程式開發員 (4-8經驗)
$20,000-$30,000
手機程式開發組長  (9-10經驗或以上