CWFileUploadManager.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. //
  2. // CWFileUploadManager.m
  3. // uploadFileDemo
  4. //
  5. // Created by hyjet on 2018/3/9.
  6. // Copyright © 2018年 uploadFileDemo. All rights reserved.
  7. //
  8. #import "CWFileUploadManager.h"
  9. //#import "CWFileStreamSeparation.h"
  10. //#import "CWUploadTask.h"
  11. //#import "CWFileManager.h"
  12. //#define plistPath [[CWFileManager cachesDir] stringByAppendingPathComponent:uploadPlist]
  13. #define default_max @"uploadMax"
  14. @interface CWFileUploadManager ()
  15. @property (nonatomic,strong)NSMutableDictionary *fileStreamDict;
  16. @property (nonatomic,strong)NSMutableDictionary *allTasks;
  17. //正在上传中的任务
  18. @property (nonatomic,strong)NSMutableDictionary *uploadingTasks;
  19. //正在等待上传的任务
  20. @property (nonatomic,strong)NSMutableDictionary *uploadWaitTasks;
  21. //已经上传完的任务
  22. @property (nonatomic,strong)NSMutableDictionary *uploadEndTasks;
  23. @property (nonatomic,assign)NSInteger uploadMaxNum;
  24. @property (nonatomic,strong)NSURL *url;
  25. @property (nonatomic,strong)NSMutableURLRequest *request;
  26. @property (nonatomic,copy)NSString *uploadLocation;
  27. @end
  28. @implementation CWFileUploadManager
  29. static CWFileUploadManager * _instance;
  30. - (NSString *)getNewPlistPath {
  31. NSString *account = [HWDataManager getStringWithKey:Const_HWAccountPhoneNumber];
  32. if (account.length != 0) {
  33. NSString *fileFolder = kPath_YunPan_Upload_Folder;
  34. return [fileFolder stringByAppendingPathComponent:@"uploadPlist.plist"];
  35. }else {
  36. HLog(@"未登录 读取plist缓存文件失败!");
  37. return @"";
  38. }
  39. }
  40. -(NSMutableDictionary *)fileStreamDict{
  41. if (!_fileStreamDict) {
  42. _fileStreamDict = [NSMutableDictionary dictionary];
  43. }
  44. return _fileStreamDict;
  45. }
  46. - (NSMutableDictionary *)allTasks
  47. {
  48. if (!_allTasks) {
  49. _allTasks = [_instance allUploadTasks];
  50. }
  51. return _allTasks;
  52. }
  53. - (NSMutableDictionary *)uploadingTasks
  54. {
  55. return [self allUploadingTasks];
  56. }
  57. - (NSMutableDictionary *)uploadWaitTasks
  58. {
  59. return [self allUploadWaitTasks];
  60. }
  61. - (NSMutableDictionary *)uploadEndTasks
  62. {
  63. return [self allUploadEndTasks];
  64. }
  65. + (instancetype)shardUploadManager {
  66. static dispatch_once_t onceToken;
  67. dispatch_once(&onceToken, ^{
  68. _instance = [[self alloc] init];
  69. [_instance registeNotification];
  70. [_instance defaultsTask];
  71. _instance.plistPath = [_instance getNewPlistPath];
  72. });
  73. return _instance;
  74. }
  75. + (CWUploadTask *)startUploadWithPath:(NSString *)path
  76. {
  77. //是否是在册任务
  78. if (![CWFileUploadManager isUploadTask:path]) {
  79. [_instance taskRecord:path];
  80. }
  81. return [_instance continuePerformTaskWithFilePath:path];
  82. }
  83. - (CWUploadTask *_Nullable)createUploadTask:(NSString *_Nonnull)filePath
  84. {
  85. //是否是在册任务
  86. if (![CWFileUploadManager isUploadTask:filePath]) {
  87. [_instance taskRecord:filePath];
  88. }
  89. return [self continuePerformTaskWithFilePath:filePath];
  90. }
  91. - (CWUploadTask *_Nullable)createUploadTask:(NSString *_Nonnull)filePath uploadLocation:(NSString *_Nonnull)uploadLocation imageData:(NSData *_Nullable)imageData {
  92. //是否是在册任务
  93. if (![CWFileUploadManager isUploadTask:filePath]) {
  94. [_instance taskRecord:filePath uploadLocation:uploadLocation imageData:imageData];
  95. }
  96. return [self continuePerformTaskWithFilePath:filePath];
  97. }
  98. //云手机上传 写入plist文件
  99. - (void)createUploadTaskWithParams:(NSDictionary *)params {
  100. CWFileStreamSeparation *fileStream = [[CWFileStreamSeparation alloc] init];
  101. NSString *path = [NSString stringWithFormat:@"%@", [params objectForKey:@"path"]];
  102. fileStream.fileName = path.lastPathComponent;
  103. fileStream.fileSize = [[params objectForKey:@"length"] integerValue];
  104. fileStream.uploadDateSize = [[params objectForKey:@"length"] integerValue];
  105. fileStream.progressRate = 1.00;
  106. fileStream.bizId=[[NSUUID UUID] UUIDString];
  107. fileStream.timeStamp = [iTools getNowTimeStamp];
  108. fileStream.fileStatus = CWUploadStatusFinished;
  109. [self.fileStreamDict setObject:fileStream forKey:path.lastPathComponent];
  110. CWUploadTask *uploadTask = self.allTasks[path.lastPathComponent];
  111. if (!uploadTask) {
  112. uploadTask = [CWUploadTask initWithStreamModel:fileStream];
  113. [self.allTasks setObject:uploadTask forKey:path.lastPathComponent];
  114. }
  115. [self archerTheDictionary:_fileStreamDict file:self.plistPath];
  116. HLog(@"%@---%@", self.fileStreamDict, self.allTasks);
  117. [[NSNotificationCenter defaultCenter] postNotificationName:CWUploadTaskExeEnd object:nil userInfo:@{@"fileStream":fileStream}];
  118. }
  119. //配置全局默认的参数
  120. - (void)config:(NSMutableURLRequest *)request maxTask:(NSInteger)num
  121. {
  122. if (!request.URL) {
  123. HLog(@"request缺少URL");
  124. }
  125. [HWDataManager setIntegerWithKey:default_max value:num];
  126. self.uploadMaxNum = 3;
  127. self.url = request.URL;
  128. self.request = request;
  129. }
  130. //设置最大任务数
  131. - (void)setUploadMaxNum:(NSInteger)uploadMaxNum
  132. {
  133. if (_uploadMaxNum<3) {
  134. _uploadMaxNum = uploadMaxNum;
  135. }else if (_uploadMaxNum<0){
  136. _uploadMaxNum = 3;
  137. }else if(_uploadMaxNum>=3){
  138. _uploadMaxNum = 3;
  139. }
  140. }
  141. - (void)defaultsTask{
  142. NSInteger tmpMax = [HWDataManager getIntegerWithKey:default_max];
  143. self.uploadMaxNum = tmpMax?tmpMax:3;
  144. }
  145. /**
  146. 暂停一个上传任务
  147. */
  148. - (void)pauseUploadTask:(CWFileStreamSeparation *_Nonnull)fileStream
  149. {
  150. CWUploadTask *task = [self.allTasks objectForKey:fileStream.fileName];
  151. [task taskCancel];
  152. }
  153. /**
  154. 继续开始一个上传任务
  155. */
  156. - (void)resumeUploadTask:(CWFileStreamSeparation *_Nonnull)fileStream
  157. {
  158. CWUploadTask *task = [self.allTasks objectForKey:fileStream.fileName];
  159. [task taskResume];
  160. }
  161. /**
  162. 删除一个上传任务,同时会删除当前任务上传的缓存数据
  163. */
  164. - (void)removeUploadTask:(CWFileStreamSeparation *_Nonnull)fileStream
  165. {
  166. CWUploadTask *task = [self.allTasks objectForKey:fileStream.fileName];
  167. [task taskCancel];
  168. if ([[self.allTasks allKeys] containsObject:fileStream.fileName]) {
  169. [self.allTasks removeObjectForKey:fileStream.fileName];
  170. }
  171. if ([[self.uploadingTasks allKeys] containsObject:fileStream.fileName]) {
  172. [self.uploadingTasks removeObjectForKey:fileStream.fileName];
  173. }
  174. if (_fileStreamDict[fileStream.fileName]) {
  175. _fileStreamDict = [self unArcherThePlist:self.plistPath];
  176. }
  177. [_fileStreamDict removeObjectForKey:fileStream.fileName];
  178. [self archerTheDictionary:_fileStreamDict file:self.plistPath];
  179. // 删除本地缓存的文件
  180. NSString *fileFolder = kPath_YunPan_Upload_Folder;
  181. NSString *fileName = fileStream.fileName;
  182. NSString *fileURL = [fileFolder stringByAppendingPathComponent:fileName];
  183. // HLog(@"%@--%@", fileURL, dict[@"fullPath"]);
  184. if ([CWFileManager isExistsAtPath:fileURL]) {
  185. BOOL flag = [[NSFileManager defaultManager] removeItemAtPath:fileURL error:nil];
  186. HLog(@"上传文件删除结果:%d", flag);
  187. }else {
  188. HLog(@"上传文件删除失败 文件不存在");
  189. }
  190. }
  191. /**
  192. 暂停所有的上传任务
  193. */
  194. - (void)pauseAllUploadTask
  195. {
  196. for (CWUploadTask *task in [self.allTasks allValues]) {
  197. [task taskCancel];
  198. }
  199. }
  200. /**
  201. 启动所有上传任务
  202. */
  203. - (void)resumeAllUploadTask {
  204. if (self.allTasks.count == 0) {
  205. return;
  206. }
  207. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  208. [self.allTasks enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  209. CWUploadTask *task = obj;
  210. if (task.fileStream.fileStatus == CWUploadStatusFinished || task.fileStream.progressRate == 1) { // 已完成的任务
  211. HLog(@"该任务已完成---文件名:%@ 进度:%.2f 状态:%ld", task.fileStream.fileName, task.fileStream.progressRate, task.fileStream.fileStatus);
  212. }else { // 所有未完成任务
  213. [dic setObject:task forKey:key];
  214. [task taskResume];
  215. }
  216. }];
  217. // NSArray *array = [dic allValues];
  218. // NSArray *sortDesc = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"timeStamp" ascending:YES]];
  219. // NSArray *sortedArr = [array sortedArrayUsingDescriptors:sortDesc];
  220. }
  221. /**
  222. 删除所有的上传任务
  223. */
  224. - (void)removeAllUploadTask
  225. {
  226. for (CWUploadTask *task in [self.allTasks allValues]) {
  227. [self removeUploadTask:task.fileStream];
  228. }
  229. }
  230. /**
  231. 获取所有文件分片模型的上传任务字典
  232. */
  233. - (NSMutableDictionary<NSString*,CWUploadTask*>*_Nullable)allUploadTasks
  234. {
  235. if (self.fileStreamDict.count == 0) {
  236. self.fileStreamDict = [self unArcherThePlist:self.plistPath];
  237. }
  238. NSDictionary *tmpDict = _allTasks?_allTasks:@{};
  239. NSMutableDictionary *fileWithTasks = [CWUploadTask uploadTasksWithDict:_instance.fileStreamDict];
  240. [fileWithTasks addEntriesFromDictionary:tmpDict];
  241. return fileWithTasks;
  242. }
  243. - (NSMutableDictionary<NSString*,CWUploadTask*>*_Nullable)allUploadWaitTasks
  244. {
  245. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  246. [self.allTasks enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  247. CWUploadTask *task = obj;
  248. if (task.fileStream.fileStatus == CWUploadStatusWaiting &&
  249. task.fileStream.fileStatus != CWUploadStatusFailed) {
  250. [dic setObject:task forKey:key];
  251. }
  252. }];
  253. return dic;
  254. }
  255. - (NSMutableDictionary<NSString*,CWUploadTask*>*_Nullable)allUploadEndTasks
  256. {
  257. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  258. [self.uploadingTasks enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  259. CWUploadTask *task = obj;
  260. if (task.fileStream.fileStatus == CWUploadStatusFinished) {
  261. [dic setObject:task forKey:key];
  262. }
  263. }];
  264. return dic;
  265. }
  266. - (NSMutableDictionary<NSString*,CWUploadTask*>*_Nullable)allUploadingTasks
  267. {
  268. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  269. [self.allTasks enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  270. CWUploadTask *task = obj;
  271. if (task.fileStream.fileStatus == CWUploadStatusUpdownloading) {
  272. [dic setObject:task forKey:key];
  273. }
  274. }];
  275. return dic;
  276. }
  277. #pragma 工具方法
  278. - (CWUploadTask *)continuePerformTaskWithFilePath:(NSString *)path{
  279. //获取任务数据字段
  280. CWFileStreamSeparation *fstream = [self.fileStreamDict objectForKey:path.lastPathComponent];
  281. CWUploadTask *uploadTask = self.allTasks[path.lastPathComponent];
  282. if (!uploadTask) {
  283. uploadTask = [CWUploadTask initWithStreamModel:fstream];
  284. [self.allTasks setObject:uploadTask forKey:path.lastPathComponent];
  285. }
  286. // [uploadTask taskResume];
  287. return uploadTask;
  288. }
  289. + (BOOL)isUploadTask:(NSString *)path{
  290. _instance = [CWFileUploadManager shardUploadManager];
  291. if (![CWFileManager isFileAtPath:_instance.plistPath]) {
  292. [CWFileManager createFileAtPath:_instance.plistPath overwrite:NO];
  293. }
  294. _instance.fileStreamDict = [_instance unArcherThePlist:_instance.plistPath];
  295. if (_instance.fileStreamDict[path.lastPathComponent] == nil) {
  296. return NO;
  297. }else{
  298. return YES;
  299. }
  300. }
  301. //新建任务分片模型并存入plist文件
  302. - (CWFileStreamSeparation * _Nullable)taskRecord:(NSString *)path{
  303. CWFileStreamSeparation *file = [[CWFileStreamSeparation alloc] initFileOperationAtPath:path forReadOperation:YES];
  304. [self.fileStreamDict setObject:file forKey:path.lastPathComponent];
  305. [self archerTheDictionary:_fileStreamDict file:self.plistPath];
  306. return file;
  307. }
  308. //新建任务分片模型并存入plist文件
  309. - (CWFileStreamSeparation * _Nullable)taskRecord:(NSString *)path uploadLocation:(NSString *)uploadLocation imageData:(NSData *)imageData {
  310. CWFileStreamSeparation *file = [[CWFileStreamSeparation alloc] initFileOperationAtPath:path forReadOperation:YES uploadLocation:uploadLocation imageData:imageData];
  311. [self.fileStreamDict setObject:file forKey:path.lastPathComponent];
  312. [self archerTheDictionary:_fileStreamDict file:self.plistPath];
  313. return file;
  314. }
  315. #pragma mark - notification
  316. - (void)registeNotification{
  317. HLog(@"del 2024525 暂未做");
  318. /* hxd del 2024525 暂未做
  319. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
  320. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskExeEnd:) name:CWUploadTaskExeEnd object:nil];
  321. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskExeSuspend:) name:CWUploadTaskExeSuspend object:nil];
  322. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskExeError:) name:CWUploadTaskExeError object:nil];
  323. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accountChange) name:ChangeAccountNotification object:nil];
  324. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exchanggeAccount) name:ExchangeLoginAccountNotification object:nil];
  325. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exchanggeAccount) name:AccountLoginOutsideNotification object:nil];
  326. */
  327. }
  328. //app启动或者app从后台进入前台都会调用这个方法
  329. - (void)applicationBecomeActive{
  330. [self uploadingTasksItemExe];
  331. }
  332. - (void)taskExeSuspend:(NSNotification *)notification
  333. {
  334. CWFileStreamSeparation *fs = notification.userInfo.allValues.firstObject;
  335. [self.uploadingTasks removeObjectForKey:fs.fileName];
  336. [self.allTasks enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  337. CWUploadTask *task = obj;
  338. if (task.fileStream.fileStatus == CWUploadStatusWaiting &&
  339. self.uploadingTasks.allValues.count < self.uploadMaxNum) {
  340. [[CWFileUploadManager shardUploadManager] resumeUploadTask:task.fileStream];
  341. }
  342. }];
  343. [self allUploadingTasks];
  344. }
  345. - (void)taskExeEnd:(NSNotification *)notification
  346. {
  347. CWFileStreamSeparation *fs = notification.userInfo.allValues.firstObject;
  348. [self.uploadingTasks removeObjectForKey:fs.fileName];
  349. [self.uploadWaitTasks enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  350. CWUploadTask *task = obj;
  351. if (self.uploadingTasks.allValues.count < self.uploadMaxNum) {
  352. [task taskResume];
  353. }else{
  354. *stop = YES;
  355. }
  356. }];
  357. [self allUploadingTasks];
  358. }
  359. - (void)taskExeError:(NSNotification *)notification
  360. {
  361. CWFileStreamSeparation *fs = notification.userInfo[@"fileStream"];
  362. NSError *error = (NSError *)notification.userInfo[@"error"];
  363. [self.uploadingTasks removeObjectForKey:fs.fileName];
  364. HLog(@"taskError:%@",error);
  365. }
  366. - (void)uploadingTasksItemExe{
  367. NSDictionary *dict = [NSDictionary dictionaryWithDictionary:self.uploadingTasks];
  368. [self.uploadingTasks removeAllObjects];
  369. [dict enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  370. CWUploadTask *task = obj;
  371. [task taskResume];
  372. }];
  373. [self.uploadWaitTasks enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  374. CWUploadTask *task = obj;
  375. if (self.uploadingTasks.allValues.count<self.uploadMaxNum) {
  376. [task taskResume];
  377. }else{
  378. *stop = YES;
  379. }
  380. }];
  381. [self allUploadingTasks];
  382. }
  383. - (void)accountChange { // 修改账号
  384. self.plistPath = [self getNewPlistPath];
  385. }
  386. - (void)exchanggeAccount { // 切换账号
  387. HLog(@"切换账号");
  388. [self pauseAllUploadTask]; // 暂停所有上传任务
  389. self.plistPath = [self getNewPlistPath];
  390. [self.allTasks removeAllObjects];
  391. self.allTasks = nil;
  392. [self.fileStreamDict removeAllObjects];
  393. [self clearCookies];
  394. }
  395. // 清空Cookie
  396. - (void)clearCookies {
  397. NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  398. NSArray *cookieArray = [NSArray arrayWithArray:[cookieJar cookies]];
  399. for(id obj in cookieArray)
  400. {
  401. [cookieJar deleteCookie:obj];
  402. }
  403. }
  404. #pragma mark - tools
  405. //归档
  406. - (void)archerTheDictionary:(NSDictionary *)dict file:(NSString *)path{
  407. [HWDataManager archiveObject:dict toPlistPath:path];
  408. }
  409. //解档
  410. - (NSMutableDictionary *)unArcherThePlist:(NSString *)path{
  411. NSMutableDictionary *dic = [HWDataManager readObjectFromPlistPath:path];
  412. return dic;
  413. }
  414. #pragma mark - 相册文件写入Cache
  415. /// 将相册里的视频文件缓存到Cache
  416. - (NSString *_Nullable)writeVideoDataFromURL:(NSURL *_Nullable)url uploadLocation:(NSString *_Nullable)uploadLocation {
  417. NSString *account = [HWDataManager getStringWithKey:Const_HWAccountPhoneNumber];
  418. if (account.length != 0) {
  419. NSString *fileFolder = kPath_YunPan_Upload_Folder;
  420. NSString *originalPath = [url.absoluteString stringByReplacingOccurrencesOfString:@"file://" withString:@""];
  421. NSString *fileName;
  422. // fileName = [NSString stringWithFormat:@"%@/%@", uploadLocation,fileName];
  423. fileName = [NSString stringWithFormat:@"%@", [iTools getNowTimeStampString]];
  424. NSString *videoName = [NSString stringWithFormat:@"SZX%@.mp4", fileName];
  425. NSString *sandboxPath = [fileFolder stringByAppendingPathComponent:videoName];
  426. NSError * error = nil;
  427. BOOL isSuccess = [CWFileManager moveItemAtPath:originalPath toPath:sandboxPath overwrite:YES error:&error];
  428. HLog(@"保存相册视频文件:%@到Caches:%@是否成功:%d error:%@", originalPath, sandboxPath,isSuccess,error);
  429. return sandboxPath;
  430. }else {
  431. HLog(@"未登录 缓存视频文件失败!");
  432. return nil;
  433. }
  434. }
  435. /// 将相册里的图片文件缓存到Cache
  436. - (NSString *_Nullable)writeIamgeData:(NSData *_Nullable)data iamgeName:(NSString *_Nullable)iamgeName uploadLocation:(NSString *_Nullable)uploadLocation {
  437. NSString *account = [HWDataManager getStringWithKey:Const_HWAccountPhoneNumber];
  438. if (account.length != 0) {
  439. NSString *fileFolder = kPath_YunPan_Upload_Folder;
  440. NSString *fileName = [NSString stringWithFormat:@"SZX%@", [iTools getNowTimeStampString]];
  441. NSString *videoName = [NSString stringWithFormat:@"%@.PNG", fileName];
  442. NSString *sandboxPath = [fileFolder stringByAppendingPathComponent:videoName];
  443. BOOL isSuccess = [data writeToFile:sandboxPath atomically:YES];
  444. HLog(@"保存相册图片文件到Caches是否成功:%d", isSuccess);
  445. return sandboxPath;
  446. }else {
  447. HLog(@"未登录 缓存图片文件失败!");
  448. return nil;
  449. }
  450. }
  451. - (NSString *_Nullable)writeIamgeDataToLocal:(NSData *_Nullable)data {
  452. NSString *account = [HWDataManager getStringWithKey:Const_HWAccountPhoneNumber];
  453. if (account.length != 0) {
  454. NSString *fileFolder = kPath_YunPan_Upload_Folder;
  455. NSString *fileName = [NSString stringWithFormat:@"SZX%@", [iTools getNowTimeStampString]];
  456. NSString *videoName = [NSString stringWithFormat:@"%@.PNG", fileName];
  457. NSString *sandboxPath = [fileFolder stringByAppendingPathComponent:videoName];
  458. BOOL isSuccess = [data writeToFile:sandboxPath atomically:YES];
  459. HLog(@"保存相册图片文件到Caches是否成功:%d", isSuccess);
  460. return sandboxPath;
  461. }else {
  462. HLog(@"未登录 缓存图片文件失败!");
  463. return nil;
  464. }
  465. }
  466. @end