错误日志/奔溃日志上传功能

奔溃日志上传:

注意点:需要自己补充上传后台的内容.奔溃日志会在下次打开APP时自动将日志文件传给后台

错误日志/奔溃日志上传功能_第1张图片

错误日志上传功能:非代码性bug导致的显示问题,大部分都是后台数据异常导致界面显示异常,对关键代码处,添加解释说明的功能,及时反馈,便于测试和后台纠正

由于服务器不同,需要自己补充上传功能.该功能隔2天后自动上传,可自己修改时间


#import "BSFeedBackDataInfo.h"

#define lastSaveTime  @"lastSaveTime"

@implementation BSFeedBackDataInfo

+ (instancetype)sharedFeedBackDataInfo

{

    staticBSFeedBackDataInfo*instance =nil;

    staticdispatch_once_tonceToken;

    dispatch_once(&onceToken, ^{

        instance = [[BSFeedBackDataInfoalloc]init];

    });

    returninstance;

}

- (void)uploadDataInfoPram:(NSString*)dataInfoStr

{

    dataInfoStr = [NSStringstringWithFormat:@"%@\n",dataInfoStr];

    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];

    NSString *filePath = [documentPath stringByAppendingPathComponent:@"feedBackDataInfoPram.txt"];

    ///1.检查沙盒中是否存在feedBackDataInfoPram.txt文件

    NSFileManager *manager = [NSFileManager defaultManager];

    BOOLexisFile = [managerfileExistsAtPath:filePath];

    ///2.1如果有,则写入,并判断当前年月是否超过2日,如果超过,则上传,否则啥也不干

    if(exisFile) {

        ///a.写入文件

        [selfkeepWriteContent:dataInfoStrfilePath:filePath];

        ///b.判断当前存储时间是否超过两日

        BOOLbeyondTwoDays = [selfjudgeCurrentDayBeyondTwoData];

        if(beyondTwoDays) {

            [selfupLoadTxtFile:filePath];

            [selfdeleteTxtFile:filePath];

        }

    }else{///2.2如果没有,则创建文件,并且用年月标记日期

        [managercreateFileAtPath:filePath contents:nil attributes:nil];

        [self keepWriteContent:[self inputConfigureInfo] filePath:filePath];

        [selfkeepWriteContent:dataInfoStrfilePath:filePath];

        NSDate*date = [NSDatedate];

        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];

        formatter.dateFormat=@"yyyy-MM-dd";

        NSString*dateStr = [formatterstringFromDate:date];

        [[NSUserDefaults standardUserDefaults] setValue:dateStr forKey:lastSaveTime];

    }

}

- (BOOL)judgeCurrentDayBeyondTwoData

{

    ///1.当前日期

    NSDate*date = [NSDatedate];

    NSTimeInterval currentDateNum = [date timeIntervalSince1970];

    ///2.之前保存的日期

    NSString *lastDateStr = [[NSUserDefaults standardUserDefaults] valueForKey:lastSaveTime];

    NSDateFormatter *format = [[NSDateFormatter alloc]init];

    format.dateFormat=@"yyyy-MM-dd";

    NSDate*lastDate = [formatdateFromString:lastDateStr];

    NSTimeInterval lastDateNum = [lastDate timeIntervalSince1970];

    if(currentDateNum-lastDateNum>2*24*3600) {

        returnYES;

    }else{

        returnNO;

    }


}

- (NSString *)inputConfigureInfo

{

    NSString*accoutStr = [BSAccPasTkgetAcc];

    NSString *systemVersion = [UIDevice currentDevice].systemVersion;

    NSString*finallyStr = [NSStringstringWithFormat:@"账号:%@ 系统版本:%@\n",accoutStr,systemVersion];

    returnfinallyStr;

}

///持续的往Txt文件中写入内容

- (void)keepWriteContent:(NSString*)dataStrfilePath:(NSString*)filePath

{

    NSDate*date = [NSDatedate];

    NSDateFormatter *dateForma = [[NSDateFormatter alloc]init];

    dateForma.dateFormat=@"yyyyMMdd";

    NSString*canlendStr = [dateFormastringFromDate:date];

    dataStr = [NSStringstringWithFormat:@"%@:%@",canlendStr,dataStr];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        NSLog(@"当前线程:%@",[NSThread currentThread]);

        NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];

        if(fileHandle ==nil) {

            return;

        }

        [fileHandleseekToEndOfFile];

        NSData *data = [dataStr dataUsingEncoding:NSUTF8StringEncoding];

        [fileHandlewriteData:data];

        [fileHandlecloseFile];

    });

}

///上传错误数据日志文件

- (void)upLoadTxtFile:(NSString*)filePath

{


}

///删除错误数据日志文件

- (void)deleteTxtFile:(NSString*)filePath

{

    NSFileManager *manager = [NSFileManager defaultManager];

    [managerremoveItemAtPath:filePatherror:nil];

}

@end

获取曲线上点的类


错误日志/奔溃日志上传功能_第2张图片

#import "UIBezierPath+curved.h"

// Based on code from Erica Sadun

voidgetPointsFromBezier(void*info,constCGPathElement*element);

NSArray *pointsFromBezierPath(UIBezierPath *bpath);

#define VALUE(_INDEX_) [NSValue valueWithCGPoint:points[_INDEX_]]

#define POINT(_INDEX_) [(NSValue *)[points objectAtIndex:_INDEX_] CGPointValue]

@implementation UIBezierPath (curved)

// Get points from Bezier Curve

voidgetPointsFromBezier(void*info,constCGPathElement*element)

{

    NSMutableArray*bezierPoints = (__bridgeNSMutableArray*)info;

    // Retrieve the path element type and its points

    CGPathElementTypetype = element->type;

    CGPoint*points = element->points;


    // Add the points if they're available (per type)

    if (type != kCGPathElementCloseSubpath)

    {

        [bezierPointsaddObject:VALUE(0)];

        if ((type != kCGPathElementAddLineToPoint) &&

            (type !=kCGPathElementMoveToPoint))

            [bezierPointsaddObject:VALUE(1)];

    }

    if (type == kCGPathElementAddCurveToPoint)

        [bezierPointsaddObject:VALUE(2)];

}

NSArray *pointsFromBezierPath(UIBezierPath *bpath)

{

    NSMutableArray *points = [NSMutableArray array];

    CGPathApply(bpath.CGPath, (__bridgevoid*)points,getPointsFromBezier);

    returnpoints;

}

#pragma mark— ************************** 接口方法 ****************************

- (NSMutableArray *)pointsFromBezierPathA {

    return [pointsFromBezierPath(self) mutableCopy];

}

- (UIBezierPath*)smoothedPathWithGranularity:(NSInteger)granularity;

{

    NSMutableArray *points = [pointsFromBezierPath(self) mutableCopy];


    if(points.count<4)return[selfcopy];


    // Add control points to make the math make sense

    [pointsinsertObject:[points objectAtIndex:0] atIndex:0];

    [pointsaddObject:[pointslastObject]];


    UIBezierPath*smoothedPath = [selfcopy];

    [smoothedPathremoveAllPoints];

    [smoothedPathmoveToPoint:POINT(0)];


    for(NSUIntegerindex =1; index < points.count-2; index++)

    {

        CGPointp0 =POINT(index -1);

        CGPointp1 =POINT(index);

        CGPointp2 =POINT(index +1);

        CGPointp3 =POINT(index +2);


        // now add n points starting at p1 + dx/dy up until p2 using Catmull-Rom splines

        for(inti =1; i < granularity; i++)

        {

            floatt = (float) i * (1.0f/ (float) granularity);

            floattt = t * t;

            floatttt = tt * t;


            CGPoint pi; // intermediate point

            pi.x=0.5* (2*p1.x+(p2.x-p0.x)*t + (2*p0.x-5*p1.x+4*p2.x-p3.x)*tt + (3*p1.x-p0.x-3*p2.x+p3.x)*ttt);

            pi.y=0.5* (2*p1.y+(p2.y-p0.y)*t + (2*p0.y-5*p1.y+4*p2.y-p3.y)*tt + (3*p1.y-p0.y-3*p2.y+p3.y)*ttt);

            [smoothedPathaddLineToPoint:pi];

        }


        // Now add p2

        [smoothedPathaddLineToPoint:p2];

    }


    // finish by adding the last point

    [smoothedPathaddLineToPoint:POINT(points.count -1)];


    returnsmoothedPath;

}

@end

你可能感兴趣的:(错误日志/奔溃日志上传功能)