doproio/practice-of-ios

IOS工具篇-reveal

Klchan-me opened this issue · 0 comments

简介

Reveal 是一个界面调试工具。使用Reveal,我们可以在iOS开发时动态地查看和修改应用程序的界面。它类似Chrome的“审查元素”功能,我们不但可以在运行时看到iOS程序的界面层级关系,还可以实时地修改程序界面,不用重新运行程序就可以看到修改之后的效果。

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调试功能

Reveal连接模拟器

在AppDelegate类的application:didFinishLaunchingWithOptions:方法中,作如下3步操作(如下图所示):

6

1)点击该方法左边的行号区域,增加一个断点,之后右击该断点,选择“Edit Breakpoint”。

2)点击”Action”项边右的”Add Action”,然后输入“reveal_load_sim”

3)勾选上Options上的”Automatically continue after evaluating”选项。

Reveal连接真机

要用Reveal连接真机调试,我们需要先把Reveal的动态链接库上传到真机上。由于iOS设备有沙盒存在,所以我们只能将Reveal的动态链接库添加到工程中。

1)点击Reveal菜单栏的”Help”->”Show Reveal Library in Finder”选项,可以在Finder中显示出Reveal的动态链接库:libReveal.dylib

show-reveal-library-in-finder

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.

7

配置方式二

使用cocoaPods配置reveal

1)新建Podfile文件,并输入pod 'Reveal-iOS-SDK', :configurations => ['Debug']

8

2)在Terminal中切换到Podfile文件所在路径,pod install
3)退出xcode,打开*.xcworkspace文件

配置方式三

1)启动Reveal,选择Reveal -> Help -> Show Reveal Library in Finder。

show-reveal-library-in-finder

(2)在Xcode中打开iOS项目,将Reveal.framework拖到项目中,如果升级了Reveal,对应的Reveal.framework文件也要更新到对应的版本。

2

(3)在Xcode的Target -> Build Setting -> Other Linker Flags添加如下几个配置项
-ObjC -lz -framework Reveal

4

(4)运行项目,然后打开Reveal的界面,在左上角选择连接的设备

5