Commit b070ccbc09def4fcc5a87c9ef873e90ff71918bc

Authored by liushiyu
1 parent 27be81ef

0.1.31

CNLiveBusinessTools.podspec
... ... @@ -9,7 +9,7 @@
9 9 Pod::Spec.new do |s|
10 10 s.name = 'CNLiveBusinessTools'
11 11  
12   - s.version = '0.1.30'
  12 + s.version = '0.1.31'
13 13 s.summary = '业务工具集合组件.'
14 14  
15 15 # This description is used to generate tags and improve search results.
... ...
CNLiveBusinessTools/Classes/CNLiveRespCacheManager.h 0 → 100644
  1 +//
  2 +// CNLiveRespCacheManager.h
  3 +// CNLiveBusinessTools
  4 +//
  5 +// Created by open on 2021/12/23.
  6 +//
  7 +
  8 +#import <Foundation/Foundation.h>
  9 +
  10 +NS_ASSUME_NONNULL_BEGIN
  11 +
  12 +@interface CNLiveRespCacheManager : NSObject
  13 +
  14 +/// 获取存储在本地的数据
  15 +/// @param cacheFileName 获取的key
  16 ++ (id<NSCoding>)objectCacheWithFileName:(NSString *)cacheFileName;
  17 +
  18 +/// 存储对应的数据,⚠️⚠️⚠️以字符串,字典,数组等为最佳,并遵守<NSCoding>协议的相关自定义类,如不遵守会出现无法写入导致闪退的问题⚠️⚠️⚠️
  19 +/// @param object 写入的数据
  20 +/// @param cacheFileName 获取的key
  21 ++ (void)cachePathWithObject:(id<NSCoding>)object FileName:(NSString *)cacheFileName;
  22 +
  23 +@end
  24 +
  25 +NS_ASSUME_NONNULL_END
... ...
CNLiveBusinessTools/Classes/CNLiveRespCacheManager.m 0 → 100644
  1 +//
  2 +// CNLiveRespCacheManager.m
  3 +// CNLiveBusinessTools
  4 +//
  5 +// Created by open on 2021/12/23.
  6 +//
  7 +
  8 +#import "CNLiveRespCacheManager.h"
  9 +#import <CNLiveUserManagement/CNUserInfoManager.h>
  10 +#import <YYCategories/YYCategories.h>
  11 +#ifndef NSFoundationVersionNumber_iOS_8_0
  12 +#define NSFoundationVersionNumber_With_QoS_Available 1140.11
  13 +#else
  14 +#define NSFoundationVersionNumber_With_QoS_Available NSFoundationVersionNumber_iOS_8_0
  15 +#endif
  16 +#define CNLiveLifeCirCleViewModelManager [CNLiveLifeCirCleViewModel sharedCNLiveLifeCirCleViewModel]
  17 +
  18 +static dispatch_queue_t CNLiverequest_cache_writing_queue() {
  19 + static dispatch_queue_t queue;
  20 + static dispatch_once_t onceToken;
  21 + dispatch_once(&onceToken, ^{
  22 + dispatch_queue_attr_t attr = DISPATCH_QUEUE_SERIAL;
  23 + if (NSFoundationVersionNumber >= NSFoundationVersionNumber_With_QoS_Available) {
  24 + attr = dispatch_queue_attr_make_with_qos_class(attr, QOS_CLASS_BACKGROUND, 0);
  25 + }
  26 + queue = dispatch_queue_create("com.CNLive.general.caching", attr);
  27 + });
  28 +
  29 + return queue;
  30 +}
  31 +
  32 +
  33 +@implementation CNLiveRespCacheManager
  34 +
  35 +/// 获取存储在本地的数据
  36 +/// @param cacheFileName 获取的key
  37 ++ (id<NSCoding>)objectCacheWithFileName:(NSString *)cacheFileName
  38 +{
  39 + NSString * cachePath = [CNLiveRespCacheManager createDirectoryIfNeeded:cacheFileName];
  40 +
  41 + if ([[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:nil]) {
  42 +
  43 + NSError *error = nil;
  44 +
  45 + NSData *data = [NSData dataWithContentsOfFile:cachePath options:NSDataReadingUncached error:&error];
  46 +
  47 + if (error) return nil;
  48 +
  49 + id object = nil;
  50 +
  51 + @try {
  52 +
  53 + object = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  54 +
  55 + } @catch (NSException *exception) {}
  56 +
  57 + return object;
  58 + }
  59 + return nil;
  60 +}
  61 +
  62 +/// 存储对应的数据,⚠️⚠️⚠️以字符串,字典,数组等为最佳,并遵守<NSCoding>协议的相关自定义类,如不遵守会出现无法写入导致闪退的问题⚠️⚠️⚠️
  63 +/// @param object 写入的数据
  64 +/// @param cacheFileName 获取的key
  65 ++ (void)cachePathWithObject:(id<NSCoding>)object FileName:(NSString *)cacheFileName {
  66 +
  67 + NSString * cachePath = [CNLiveRespCacheManager createDirectoryIfNeeded:cacheFileName];
  68 +
  69 + dispatch_async(CNLiverequest_cache_writing_queue(), ^{
  70 + @try {
  71 +
  72 + NSData * data = [NSKeyedArchiver archivedDataWithRootObject:object];
  73 + if (data) [data writeToFile:cachePath atomically:YES];
  74 +
  75 + } @catch (NSException *exception) {
  76 + NSLog(@"存储失败=>%@",exception);
  77 + }
  78 + });
  79 +}
  80 ++ (NSString *)createDirectoryIfNeeded:(NSString *)cacheFileName {
  81 +
  82 + NSString *pathOfLibrary = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  83 + NSString *path = [pathOfLibrary stringByAppendingPathComponent:[NSString stringWithFormat:@"CNLiveGeneRespCache/%@",[CNUserShareModel.uid isNotBlank]?CNUserShareModel.uid:@"no_login"]];
  84 +
  85 + NSFileManager *fileManager = [NSFileManager defaultManager];
  86 + BOOL isDir;
  87 + if (![fileManager fileExistsAtPath:path isDirectory:&isDir]) {
  88 + [CNLiveRespCacheManager createBaseDirectoryAtPath:path];
  89 + } else {
  90 + if (!isDir) {
  91 + NSError *error = nil;
  92 + [fileManager removeItemAtPath:path error:&error];
  93 + [CNLiveRespCacheManager createBaseDirectoryAtPath:path];
  94 + }
  95 + }
  96 + path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.metadata",[cacheFileName md5String]]];
  97 +
  98 + return path;
  99 +}
  100 ++ (void)createBaseDirectoryAtPath:(NSString *)path {
  101 + NSError *error = nil;
  102 + [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES
  103 + attributes:nil error:&error];
  104 + if (error) {
  105 + NSLog(@"error = %@", error);
  106 + }
  107 +}
  108 +@end
... ...
Example/CNLiveBusinessTools/CNLiveViewController.m
... ... @@ -9,6 +9,7 @@
9 9 #import "CNLiveViewController.h"
10 10 #import <QMUIKit/QMUIKit.h>
11 11 #import "CNLiveEscpTools.h"
  12 +#import <YYCategories/YYCategories.h>
12 13 //#import <CNLiveBusinessTools/CNLiveQQEmotionManager.h>
13 14  
14 15 #define KScreenWidth ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width)
... ... @@ -37,10 +38,10 @@
37 38 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
38 39 {
39 40 [super touchesBegan:touches withEvent:event];
40   - NSString * s = @"http://wjjh5test.cnlive.com/smartappLandingpage.html?title=1234&imageUrl=https://b.bdstatic.com/searchbox/mappconsole/image/20181105/1541398769-33490.png&swanId=lDvbSAZzaa8xPTQ8M0EquG1xos75HGvU%2F%2Fpages%2FaudioDetail%2FaudioDetail%3Fshare%3D1%26contentId%3D1240263%26rowId%3D1%26pubDate%3D2021%2D11%2D01%26assignTag%3D%E5%90%8D%E7%AF%87%E8%B5%8F%E6%9E%90&type=smartapp";
  41 + NSString * s = @"swanId=lDvbSAZzaa8xPTQ8M0EquG1xos75HGvU//pages/audioDetail/audioDetail?share=1&contentId=1240263&rowId=1&pubDate=2021-11-01&assignTag=%E5%90%8D%E7%AF%87%E8%B5%8F%E6%9E%90"; //@"swanId=lDvbSAZzaa8xPTQ8M0EquG1xos75HGvU%2F%2Fpages%2Fsubcate%2Fsubcate%3Fcatename%3D%E8%81%8C%E5%9C%BA%E8%8B%B1%E8%AF%AD"; //@"http://wjjh5test.cnlive.com/smartappLandingpage.html?title=1234&imageUrl=https://b.bdstatic.com/searchbox/mappconsole/image/20181105/1541398769-33490.png&swanId=lDvbSAZzaa8xPTQ8M0EquG1xos75HGvU%2F%2Fpages%2FaudioDetail%2FaudioDetail%3Fshare%3D1%26contentId%3D1240263%26rowId%3D1%26pubDate%3D2021%2D11%2D01%26assignTag%3D%E5%90%8D%E7%AF%87%E8%B5%8F%E6%9E%90&type=smartapp";
41 42 // swanId=lDvbSAZzaa8xPTQ8M0EquG1xos75HGvU//pages/audioDetail/audioDetail?share=1&contentId=1240263&rowId=1&pubDate=2021-11-01&assignTag=%E5%90%8D%E7%AF%87%E8%B5%8F%E6%9E%90
42 43 NSString * temp_s = [CNLiveEscpTools esp:s];
43   - NSString * temp_s_un = [CNLiveEscpTools unesp:temp_s];
  44 + NSString * temp_s_un = [s stringByURLDecode];//[CNLiveEscpTools unesp:s];
44 45 NSLog(@"%@",temp_s);
45 46 NSLog(@"%@",temp_s_un);
46 47 }
... ...