123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- //
- // addLogObject.m
- // 双子星云手机
- //
- // Created by xd h on 2024/4/11.
- //
- #import "addLogObject.h"
- #import "netWorkManager.h"
- #import "connectDeviceManager.h"
- #import "fileUploadToFileCenterModel.h"
- #import <SSZipArchive/SSZipArchive.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)gotoAddLogFunBySuccess:(AddLog_Success)success
- {
- //HLog(@"hxd beginTime");
- if(!_canUploadNowType){
- success(@"");
- return;
- }
-
- //一小时内只能上传一次
- NSNumber *preSecondNum = [HWDataManager getNumberWithKey:stringKeyAddSn(@"addLog")];
- if(preSecondNum){
- long seconds = [iTools getNowTimeStamp];
- if(seconds - preSecondNum.longValue <= 60*60){
- success(@"");
- return;
- }
- }
-
- _canUploadNowType = NO;
-
- NSString *zipPath = [NSString stringWithFormat:@"%@/logs/archive.zip",CachesPatch];
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- // 检查文件是否存在
- BOOL fileExists = [fileManager fileExistsAtPath:zipPath];
- if (fileExists) {
- // 删除文件
- NSError *error = nil;
- BOOL success = [fileManager removeItemAtPath:zipPath error:&error];
- if (success) {
- HLog(@"文件已成功删除: %@", zipPath);
- } else {
- HLog(@"删除文件失败: %@", [error localizedDescription]);
- }
- }
-
- //2.读取日志
- //NSString *ruiyunLogPath = [NSString stringWithFormat:@"%@/logs/debug_0.log",CachesPatch];
- NSString *ruiyunLogPath = [NSString stringWithFormat:@"%@/logs/webrtc_log_0",CachesPatch];
-
- NSString *ruiyunLogPath2 = [NSString stringWithFormat:@"%@/logs/app.log",CachesPatch];
-
- //3. 将文件压缩成ZIP
- NSArray *filesToZip = @[ruiyunLogPath, ruiyunLogPath2];
- [SSZipArchive createZipFileAtPath:zipPath withFilesAtPaths:filesToZip];
-
- NSData *logData = [NSData dataWithContentsOfFile:zipPath];
-
- HLog(@"%@",logData);
-
- if(!logData || [logData length]==0){
- _canUploadNowType = YES;
- success(@"");
- return;
- }
-
- //4.上传到文件中心
- NSMutableDictionary *paraDict = [NSMutableDictionary new];
-
- NSString *snStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
- if(!snStr){
- snStr = [iTools getNowTimeString];
- }
- NSString*filename = [[NSString alloc] initWithFormat:@"%@_ios.log",snStr];
-
- [paraDict setValue:filename forKey:@"filename"];
- [paraDict setValue:@7 forKey:@"days"];
-
- KWeakSelf
- [[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){
- [weakSelf markAddLogTimeFun];
- //[self uploadKeyToServerFunBy:fileKey];
- success(fileKey);
- }
- else{
- success(@"");
- self->_canUploadNowType = YES;
- }
- }
- else{
- success(@"");
- self->_canUploadNowType = YES;
- }
-
- } faild:^(NSError * _Nonnull error) {
- success(@"");
- self->_canUploadNowType = YES;
- }];
-
- //[self uploadKeyToServerFunBy:@"LowLevelMultipartUpload_43025714606656109698"];
- }
- //3.拿到key上传到盒子服务器
- //- (void)uploadKeyToServerFunBy:(NSString*)fileKey
- //{
- // NSMutableDictionary *paraDict = [NSMutableDictionary new];
- // [paraDict setValue:@"ios" forKey:@"type"];
- //
- // NSString *snStr = ksharedAppDelegate.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
|