iPhoneRemoteDebugging

最近在網路上找資料,
又看到一個有趣有用的東西,
有人整理好一個 shell script ,
只要執行它就可以 Remote Debugging iOS simulator 上 Mobile Safari 的網站,
這個方法的限制在於只能在 simulator 上執行,
但是好處是連上次介紹的 weinre 都不用裝了,
在開發階段,
也許是 debug 的好方式,
以下是其步驟。

1. create shell script, 內容如下:

#!/bin/bash

# Open iPhone Simulator on default location for XCode 4.3 if found

[[ -d /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/ ]] &&
open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app

# Open iPhone Simulator on default location for XCode 4.2 if found
[[ -d /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/ ]] &&
open /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app

# Open mobile safari
echo Open mobile safari on emulator and press return
read

# Plug debug to MobileSafari.app
echo Debugging
MobileSafari_PID=$(ps x | grep "MobileSafari" | grep -v grep | awk '{ print $1 }')

if [ "$MobileSafari_PID" == "" ]; then
echo "Mobile Safari.app must be running in the Simulator to enable the remote inspector."
exit
else

cat <<EOM | gdb -quiet > /dev/null
attach $MobileSafari_PID
p (void *)[WebView _enableRemoteInspector]
detach
EOM
fi

# Open debugger in Safari.app
open -a /Applications/Safari.app http://localhost:9999

 

2. chmod a+x 該 script 檔案 

3. 開啟 mac 上的 iOS  simulator

4. 執行 該 script ex: ./iosd.sh

[ddsakura@]$ ./iosd.sh
Open mobile safari on emulator and press return

Debugging

5. 接下來這個 script 就會開啟 safari ,並開啟 http://localhost:9999/

safariDebugConsole

 

6, 這個時候就可以看到 網頁列表,點進去就可以看到如 firebug 的 debug 介面,接下來就可以開始進行 網頁 remote debugging 的動作了!

remoteDebugging

同場加映裝 simulator 畫面的好工具,
iOS simulator cropper
http://www.curioustimes.de/iphonesimulatorcropper/ 
本文第一張圖就是透過它來裝的。

希望本文對 進行 mobile web 開發的朋友有所幫助 :)

Technorati Tags: development, iOS, remote debugging, Safari, Mobile Safari, script, engineering

arrow
arrow
    全站熱搜

    賽拉維‧柯南 發表在 痞客邦 留言(0) 人氣()