ios 利用Reveal来调试界面2--真机调试(步骤详解)

使用真机调试我们的App界面,如果你的真机是没有越狱的设备,那么使用Reveal来调试UI的步骤是最麻烦的。


打开Reveal的库位置

取Reveal的库

拖库进项目

1、如“拖库进项目”图所示,把Reveal的库拖到我们项目中来。


选择添加的方法

2、如“选择添加的方法”所示,不要把库加到我们App的target里面。


添加到Bundle Resource

3、如“添加到Bundle Resource”图所示,将Reveal的库添加到Bundle Resource。


选择添加到Bundle Resource

4、如“选择添加到Bundle Resource”所示,选择对应的Reveal的库到Bundle Resource。


添加Reveal库成功

5、如“添加Reveal库成功”图所示,当Bundle Resources出现了Reveal库的时候就添加成功了。


添加对应的系统库

6、如“添加对应的系统库”所示,添加Reveal运行时所需要的系统库。


添加Reveal运行脚本

7、如“添加Reveal运行脚本”所示,接下来是添加Reveal的运行脚本,是不是感觉到麻烦了,如果你有更好调试非越狱真机的方法欢迎告知我,谢谢!


写入Reveal对应的脚本

8、如“写入Reveal对应的脚本”所示,写入Reveal运行时候需要的脚本,脚本内容如下:

set -e

if [ -n “${CODE_SIGN_IDENTITY}” ]; then

codesign -fs “${CODE_SIGN_IDENTITY}” “${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/libReveal.dylib”

fi


加载方法

在生命周期方法里面调用加载方法

9、如“加载方法”图所示,需要在AppDelegate里面写对应的Reveal加载方法,我使用的是Swift版本的,当然也有OC版本的。然后如“在生命周期方法里面调用加载方法”图所示,需要在生命周期方法里面调用Reveal的加载方法。各个版本加载方法现提供如下(需要注意的是不要在发布版本去加载Reveal,因为它仅适合调试):

Swift:

// MARK: - Reveal
 
func loadReveal() {
 
if NSClassFromString("IBARevealLoader") == nil {
 
let revealLibName = "libReveal" // or "libReveal-tvOS" for tvOS targets
 
let revealLibExtension = "dylib"
 
var error: String?
 
if let dylibPath = NSBundle.mainBundle().pathForResource(revealLibName, ofType: revealLibExtension) {
 
print("Loading dynamic library \(dylibPath)")
 
let revealLib = dlopen(dylibPath, RTLD_NOW)
 
if revealLib == nil {
 
error = String(UTF8String: dlerror())
 
}
 
} else {
 
error = "File not found."
 
}
 
if error != nil {
 
let alert = UIAlertController(title: "Reveal library could not be loaded",
 
message: "\(revealLibName).\(revealLibExtension) failed to load with error: \(error!)",
 
preferredStyle: .Alert)
 
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
 
UIApplication.sharedApplication().windows.first?.rootViewController?.presentViewController(alert, animated: true, completion: nil)
 
}
 
}
 
}

 

Objective-C:

#import
 
#pragma mark - Reveal
 
- (void)loadReveal
 
{
 
if (NSClassFromString(@"IBARevealLoader") == nil)
 
{
 
NSString *revealLibName = @"libReveal"; // or @"libReveal-tvOS" for tvOS targets
 
NSString *revealLibExtension = @"dylib";
 
NSString *error;
 
NSString *dyLibPath = [[NSBundle mainBundle] pathForResource:revealLibName ofType:revealLibExtension];
 
if (dyLibPath != nil)
 
{
 
NSLog(@"Loading dynamic library: %@", dyLibPath);
 
void *revealLib = dlopen([dyLibPath cStringUsingEncoding:NSUTF8StringEncoding], RTLD_NOW);
 
if (revealLib == NULL)
 
{
 
error = [NSString stringWithUTF8String:dlerror()];
 
}
}
 
else
 
{
 
error = @"File not found.";
 
}
 
if (error != nil)
 
{
 
NSString *message = [NSString stringWithFormat:@"%@.%@ failed to load with error: %@", revealLibName, revealLibExtension, error];
 
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Reveal library could not be loaded"
 
message:message
 
preferredStyle:UIAlertControllerStyleAlert];
 
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
 
[[[[[UIApplication sharedApplication] windows] firstObject] rootViewController] presentViewController:alert animated:YES completion:nil];
 
}
 
}
 
}

 


成功运行结果
 
10、保证你的电脑和你的真机在同一个网段内,然后运行你的App,在Reveal中选择你的设备,稍等片刻,你的Reveal就会出现对应的UI界面了,如“成功运行结果”界面所示(我的运行设备是iPad)。使用Cmd+R快捷键可以刷新你的Reveal界面。

非越狱真机调试是最麻烦的,以前真机还可以使用断点来调试的,现在都不能用了。不再纠结这个了,如果你的设备是越狱设备,那么恭喜你,你要使用Reveal简直是轻松加esay。点开链接一键配置,用Reveal Loader配合Reveal调试App会 有惊喜。这个是Richard Heard这位开发者开发的一个Reveal插件,你只需要安装这个插件,保证你的电脑和你的真机在同一个网段内,然后选择你想要调试的任何App(对, 没错,不是你自己家的App也可以搞,只有你想不到,没有你看不到的,哈哈哈,巨大福利)。

posted @ 2016-08-09 23:25  码锋窝  阅读(1385)  评论(0编辑  收藏  举报