#Reveal能做什么
Reveal是一个iOS程序界面调试工具。
它的好处在于,Reveal类似Chrome的“审查元素”功能,对于我们手写ui的调试好处是显而易见的。
通过使用它,我们可以方便的调试和修改应用界面。
#下载Reveal
我们可以直接通过Reveal官网来进行下载使用它,非常方便,下载后解压就可以得到。
下面是官网链接:
值得提醒的是我们解压后,reveal.app的位置和我们之后的配置有关。
#配置Reveal
在各种教程里,我推荐通过配置.lldbinit文件来使用Reveal.
原因在于,它不用通过修改Xcode工程就可以加载和使用Reveal。
一,进入当前用户目录,输入新建.lldbinit文件的命令:
touch ~/.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:0x4], 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];
以下是关于配置命令的解释:
reveal_load_sim 这个只在iOS模拟器上有效。它从Reveal的应用程序bundle中找到并加载libReveal.dylib(请确保你把Reveal安装到了系统的Application文件夹,如果你换地方了,你修改上述的文件)。
reveal_load_dev 这个命令在iOS设备和模拟器上都有效。不过,它需要你在Build Phase中的的Copy Bundle Resources中加上libReveal.dylib,请确保没有放到Link Binary With Libraries这个地方。
reveal_start 这个命令发出一个通知启动Reveal Server。
reveal_stop 这个命令发出一个通知停止Reveal Serve
#在工程中调用Reveal
打开我们的iOS工程,在AppDelegate.m中,找到didFinishLaunchingWithOptions方法。在其中设下一个断点。
原因在于:
只有在iOS应用发出了UIApplicationDidFinishLaunchingNotification通知之后,比如应用的delegate已经处理过application::didFinishLaunchingWithOptions:之后。才能调用上面的reveal_ load_*命令,然后再调用reveal _start启动Reveal。
1.增加断点,并右击给断点,选择”Edit Brakpoint”:
2.单击”Action”旁边的”add Action”,输入”reveal_loadsim”:
3.勾选“Options”上的”Automatically continue after evaluating”
#运行Reval
在做完以上的准备之后,只需要运行模拟器。打开Reveal,就可以使用了。
如果配置成功我们会在Xcode的输出中看到类似这样的提示:
然后在Reveal的左上角,看到启动的模拟器:
选择就可以连接使用了。最后的效果如下图: