美文网首页
Reveal APP(有源码)

Reveal APP(有源码)

作者: 百省 | 来源:发表于2016-08-31 17:24 被阅读28次

在有源码的情况下使用Reveal查看自己APP界面层次,可使用以下步骤实现

本文部分图片来源于(http://www.jianshu.com/p/290af2bf5afb

1.下载Reveal (下载地址:https://pan.baidu.com/s/1sjNySjz
2.找到Reveal动态库

取动态库.jpg
取Reveal库.png

3.把动态库添加到工程中(注意不要勾选target)


添加到project.jpeg
4.把动态库添加到bundle Resource
添加到bundle Resource_1.jpeg 添加到bundle Resource_2.jpeg 添加到bundle Resource_完成.jpeg

5.添加系统库

添加系统库.jpeg

6.添加脚本(下面途中第二个复选框不要勾)

添加脚本.jpeg

脚本源码:

set -e

if [ -n "${CODE_SIGN_IDENTITY}" ]; then

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

fi

7.在

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions函数中加载reveal动态库
屏幕快照 2016-08-31 下午5.21.22.png

源码:

- (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];
            
        }
        
    }
    
}

相关文章

网友评论

      本文标题:Reveal APP(有源码)

      本文链接:https://www.haomeiwen.com/subject/yvtcettx.html