iOS 开发~项目常用,经典内容收集

iOS -> 友盟错误分析

2017-08-23  本文已影响1965人  大王叫我来巡山_Cong
修复.jpg

前提

正题

错误详情.png

错误列表 点击进去基本上都是这个样子,这并不能方便我们及时定位到错误地方。

解决

最后

针对错误的地方 然后进行修复就OK了。

解析下工具代码(应群主的要求)秦小风

NSString *archivesPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Developer/Xcode/Archives/"];
    NSURL *bundleURL = [NSURL fileURLWithPath:archivesPath];
    NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtURL:bundleURL
                                          includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey]
                                                             options:NSDirectoryEnumerationSkipsHiddenFiles
                                                        errorHandler:^BOOL(NSURL *url, NSError *error)
    {
        if (error) {
            NSLog(@"[Error] %@ (%@)", error, url);
            return NO;
        }

        return YES;
    }];
    _archiveFilesInfo = [NSMutableArray arrayWithCapacity:1];
    for(NSString *filePath in filePaths){
        ArchiveInfo *archiveInfo = [[ArchiveInfo alloc] init];

        NSString *fileName = filePath.lastPathComponent;
        //支持 xcarchive 文件和 dSYM 文件。
        if ([fileName hasSuffix:@".xcarchive"]){
            archiveInfo.archiveFilePath = filePath;
            archiveInfo.archiveFileName = fileName;
            archiveInfo.archiveFileType = ArchiveFileTypeXCARCHIVE;
            [self formatArchiveInfo:archiveInfo];
        }else if([fileName hasSuffix:@".dSYM"]){
            archiveInfo.dSYMFilePath = filePath;
            archiveInfo.dSYMFileName = fileName;
            archiveInfo.archiveFileType = ArchiveFileTypeDSYM;
            [self formatDSYM:archiveInfo];
        }else{
            continue;
        }

        [_archiveFilesInfo addObject:archiveInfo];
    }

点击 分析 按钮,程序到底做了什么?

核心代码

- (NSString *)runCommand:(NSString *)commandToRun
{
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/bin/sh"];
    
    NSArray *arguments = @[@"-c",
            [NSString stringWithFormat:@"%@", commandToRun]];
//    NSLog(@"run command:%@", commandToRun);
    [task setArguments:arguments];
    
    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput:pipe];
    
    NSFileHandle *file = [pipe fileHandleForReading];
    
    [task launch];
    
    NSData *data = [file readDataToEndOfFile];
    
    NSString *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    return output;
}
xcrun atos -arch arm64 -o "Slide Address" 错误内存地址

手动通过 atos 工具(Mac 平台)来输出错误地址

iOS打包后的文件会有dSYMs这个文件夹

原理

这个工具是 dSYMTools

下载地址

上一篇 下一篇

猜你喜欢

热点阅读