// // addLogObject.m // 双子星云手机 // // Created by xd h on 2024/4/11. // #import "addLogObject.h" #import "netWorkManager.h" #import "connectDeviceManager.h" #import "fileUploadToFileCenterModel.h" @implementation addLogObject static addLogObject *addlog_ShareInstance = nil; +(addLogObject *)shareInstance; { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ addlog_ShareInstance = [[addLogObject alloc]init]; }); return addlog_ShareInstance; } - (id)init { self = [super init]; if (self) { _canUploadNowType = YES; } return self; } //1.读取日志 //2.上传到文件中心 //3.拿到key上传到盒子服务器 - (void)gotoAddLogFun { //HLog(@"hxd beginTime"); if(!_canUploadNowType){ return; } //一小时内只能上传一次 NSNumber *preSecondNum = [HWDataManager getNumberWithKey:stringKeyAddSn(@"addLog")]; if(preSecondNum){ long seconds = [iTools getNowTimeStamp]; if(seconds - preSecondNum.longValue <= 60*60){ return; } } _canUploadNowType = NO; //1.读取日志 NSString *ruiyunLogPath = [NSString stringWithFormat:@"%@/logs/debug_0.log",CachesPatch]; NSData *logData = [NSData dataWithContentsOfFile:ruiyunLogPath]; HLog(@"%@",logData); if(!logData || [logData length]==0){ _canUploadNowType = YES; return; } //2.上传到文件中心 NSMutableDictionary *paraDict = [NSMutableDictionary new]; NSString *snStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn; if(!snStr){ snStr = [iTools getNowTimeString]; } NSString*filename = [[NSString alloc] initWithFormat:@"%@_ios.log",snStr]; [paraDict setValue:filename forKey:@"filename"]; [[netWorkManager shareInstance] doUploadFileToFileServiceWithParams:paraDict data:logData success:^(id _Nonnull responseObject) { HLog(@"%@",responseObject); fileUploadToFileCenterModel *model = [[fileUploadToFileCenterModel alloc] initWithDictionary:responseObject error:nil]; if(model.code == 200){ NSString * fileKey = model.data.fileKey; if(fileKey && fileKey.length >0){ [self uploadKeyToServerFunBy:fileKey]; } else{ self->_canUploadNowType = YES; } } else{ self->_canUploadNowType = YES; } } faild:^(NSError * _Nonnull error) { self->_canUploadNowType = YES; }]; //[self uploadKeyToServerFunBy:@"LowLevelMultipartUpload_43025714606656109698"]; } //3.拿到key上传到盒子服务器 - (void)uploadKeyToServerFunBy:(NSString*)fileKey { NSMutableDictionary *paraDict = [NSMutableDictionary new]; [paraDict setValue:@"ios" forKey:@"type"]; NSString *snStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn; if(!snStr){ _canUploadNowType = YES; return; } [paraDict setValue:snStr forKey:@"sn"]; [paraDict setValue:fileKey forKey:@"key"]; KWeakSelf [[netWorkManager shareInstance] CommonPostCallBackCode:addLogFun Parameters:paraDict success:^(id _Nonnull responseObject) { SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; if(model.code == 0){ [weakSelf markAddLogTimeFun]; } else{ self->_canUploadNowType = YES; } } failure:^(NSError * _Nonnull error) { self->_canUploadNowType = YES; }]; } - (void)markAddLogTimeFun { // long seconds = [iTools getNowTimeStamp]; NSNumber *secondsNum = [NSNumber numberWithLong:seconds]; if(secondsNum){ [HWDataManager setNumberWithKey:stringKeyAddSn(@"addLog") value:secondsNum]; } _canUploadNowType = YES; //HLog(@"hxd endTime"); } @end