iOS開發中集成Reveal

【轉】http://blog.devzeng.com/blog/ios-reveal-integrating.htmlphp

配置方式一簡介有效。html

Reveal 是一個界面調試工具。使用Reveal,咱們能夠在iOS開發時動態地查看和修改應用程序的界面。它相似Chrome的「審查元素」功能,咱們不但能夠在運行時看到iOS程序的界面層級關係,還能夠實時地修改程序界面,不用從新運行程序就能夠看到修改以後的效果。ios

在使用時,咱們將Reveal鏈接上模擬器或真機上正在運行的iOS程序,而後就能夠查看和調試iOS程序的界面。vim

reveal-hero.png

###下載安裝xcode

Releal官方提供試用版本,免費試用期是30天,功能和正式版沒有差異.點此下載app

###配置Reveal工具

####一、配置方式一post

(1)啓動Reveal,選擇Reveal -> Help -> Show Reveal Library in Finder測試

show-reveal-library-in-finder.jpg

(2)在Xcode中打開iOS項目,將Reveal.framework拖到項目中,若是升級了Reveal,對應的Reveal.framework文件也要更新到對應的版本。ui

add-resource-to-project.jpg

(3)選擇Target -> Build Phases -> Link Binary With Libraries將Reveal.framework移除。經測試本步驟不是必須的

remove-framework-from-project.jpg

(4)在Xcode的Target -> Build Setting -> Other Linker Flags添加以下幾個配置項

-ObjC -lz -framework Reveal

add-linker-flags.jpg

(5)運行項目,而後打開Reveal的界面,在左上角選擇鏈接的設備

reveal-app-chooser.jpg

而後就能夠看到實際的運行效果

reveal_demo.png

####二、配置方式二

Reveal官方介紹了好幾種辦法使Reveal鏈接模擬器,都須要修改工程文件。但若是修改了工程文件,就須要參與項目開發的全部人都裝有Reveal,下面介紹一種比較方便的方式來集成Reveal,步驟以下:

首先打開Terminal,輸入vim ~/.lldbinit建立一個名爲.lldbinit的文件,而後將以下內容輸入到該文件中:

command alias reveal_load_sim expr (void*)dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 0x2);
command alias reveal_load_dev expr (void*)dlopen([(NSString*)[(NSBundle*)[NSBundle mainBundle]               pathForResource:@"libReveal" ofType:@"dylib"] cStringUsingEncoding:0    x4], 0x2);
command alias reveal_start expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter]           postNotificationName:@"IBARevealRequestStart" object:nil];
command alias reveal_stop expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter]            postNotificationName:@"IBARevealRequestStop" object:nil];

該步驟實際上是爲lldb設置了4個別名,爲了後續方便操做,這4個別名意義以下:

reveal_load_sim 爲模擬器加載reveal調試用的動態連接庫

reveal_load_dev 爲真機加載reveal調試用的動態連接庫

reveal_start 啓動reveal調試功能

reveal_stop 結束reveal調試功能

(1)Reveal鏈接模擬器

reveal_load_sim.png

在AppDelegate類的application:didFinishLaunchingWithOptions:方法中,做以下3步操做(以下圖所示):

1)點擊該方法左邊的行號區域,增長一個斷點,以後右擊該斷點,選擇「Edit Breakpoint」。

2)點擊」Action」項邊右的」Add Action」,而後輸入「reveal_load_sim」

3)勾選上Options上的」Automatically continue after evaluating」選項。

(2)Reveal鏈接真機

要用Reveal鏈接真機調試,咱們須要先把Reveal的動態連接庫上傳到真機上。因爲iOS設備有沙盒存在,因此咱們只能將Reveal的動態連接庫添加到工程中。

1)點擊Reveal菜單欄的」Help」->」Show Reveal Library in Finder」選項,能夠在Finder中顯示出Reveal的動態連接庫:libReveal.dylib

show-reveal-library-in-finder.jpg

2)調整libReveal.dylib的引用方式,這裏咱們只須要將libReveal.dylib文件拷貝到Sandbox中,可是咱們在引入libReveal.dylib的時候Xcode默認是以Link Binary With Libraries的方式的,實際上應該是Copy Bundle Resources,因此應該先將libReveal.dylibLink Binary With Libraries中移除掉,而後在Copy Bundle Resources中添加。

3)安裝以前處理模擬器的方式,將配置文件改爲reveal_load_dev.

reveal_load_dev.png

啓動後在控制檯會出現以下內容:

reveal_load_console.png

###參考資料

一、《使用Reveal來查看、修改、調試iOS應用》

二、《Integrating Reveal without modifying your Xcode project》

三、《Reveal查看任意app的高級技巧》

相關文章
相關標籤/搜索