本文转自Reveal-iOS页面调试利器
1.首先下载Reveal
2.新建 .lldbinit 文件
在 Home 目录(就是 ~ 目录)下新建 .lldbinit 文件,然后加入下面的内容:
command alias swift_reveal_load_sim expr dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 2)
command alias swift_reveal_load_dev expr dlopen(NSBundle.mainBundle().pathForResource("libReveal", ofType: "dylib")!, 2)
command alias swift_reveal_start expr NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStart", object: nil)
command alias swift_reveal_stop expr NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStop", object: nil)
command alias objc_reveal_load_sim expr (void*)dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 0x2);
command alias objc_reveal_load_dev expr (void*)dlopen([(NSString*)[(NSBundle*)[NSBundle mainBundle] pathForResource:@"libReveal" ofType:@"dylib"] cStringUsingEncoding:0x4], 0x2);
command alias objc_reveal_start expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];
command alias objc_reveal_stop expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStop" object:nil];
swift_reveal_load_sim
为模拟器加载 Reveal 的动态链接库,以便可以用 Reveal 动态调试模拟器运行的应用程序的页面结构。用于 Swift 代码的工程;
swift_reveal_load_dev
为真机加载 Reveal 的动态链接库,以便可以用 Reveal 动态调试模拟器运行的应用程序的页面结构。用于 Swift 代码的工程;
swift_reveal_start
启动 Reveal 调试功能;
swift_reveal_stop
结束 Reveal 调试功能;
objc_reveal_load_sim
作用与 swift_reveal_load_sim 相同,只不过该命令用于 Obejective-C 代码的工程;
objc_reveal_load_dev
作用与 swift_reveal_load_dev 相同,只不过该命令用于 Obejective-C 代码的工程;
objc_reveal_start
作用与 swift_reveal_start 相同,只不过该命令用于 Obejective-C 代码的工程;
objc_reveal_stop
作用与 swift_reveal_stop 相同,只不过该命令用于 Obejective-C 代码的工程;
在 AppDelegate application:didFinishLaunchingWithOptions: 方法的中,按如下操作:
(1) 在 application:didFinishLaunchingWithOptions: 方法第一行代码前面点击行号添加一个断点,如下图:

使用模拟器时配置:注意下面的选择Options 中的 "Automatically continue after evaluating actions"。

打开reveal:

将"libReveal.dylib"拖拽到工程中

拖入后"libReveal.dylib"会自动加到Target -> Build Phases -> Link Binary With Libraries中,需要从中删除然后加到Target -> Build Phases -> Copy Bundle Resources 中。
运行项目后不会在上面的断点处停止,直接打开reveal选择链接设备
如果上面无法正常运行,可以在 Target -> Build Phases -> 添加一个 Run Script,并将以下内容填入:
set -e
if [ -n "${CODE_SIGN_IDENTITY}" ]; then
codesign -fs "${CODE_SIGN_IDENTITY}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/libReveal.dylib"
fi


网友评论