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的高级技巧》

相关文章
相关标签/搜索