diff --git a/Podfile b/Podfile index 9b6cc7ff..ce5af41c 100644 --- a/Podfile +++ b/Podfile @@ -65,7 +65,7 @@ target 'YuMi' do pod 'ZLCollectionViewFlowLayout' pod 'WMZDropDownMenu' pod 'TABAnimated' - + pod 'YuMi',:path=>'yum' end post_install do |installer| diff --git a/yum/Class/UIImage+load.h b/yum/Class/UIImage+load.h new file mode 100644 index 00000000..b333c4d6 --- /dev/null +++ b/yum/Class/UIImage+load.h @@ -0,0 +1,19 @@ +// +// UIImage+load.h +// YM +// +// Created by YM on 2023/1/8. +// +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface UIImage (load) + + + +@end + +NS_ASSUME_NONNULL_END diff --git a/yum/Class/UIImage+load.m b/yum/Class/UIImage+load.m new file mode 100644 index 00000000..a62a114e --- /dev/null +++ b/yum/Class/UIImage+load.m @@ -0,0 +1,91 @@ +// +// UIImage+load.m +// YM +// +// Created by YM on 2023/1/8. +// +// + +#import "UIImage+load.h" +#import + +@implementation UIImage (load) ++ (void)load{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + [UIImage yumi_swizzleInstanceMethod:[UIImage class] original:@selector(imageNamed:) swizzled:@selector(imgesNameHook:)]; + if (@available(iOS 13.0, *)) { + [UIImage yumi_swizzleInstanceMethod:[UIImage class] original:@selector(imageNamed:inBundle:withConfiguration:) swizzled:@selector(yumi_imgename:inBundle:withConfiguration:)]; + } + [UIImage yumi_swizzleInstanceMethod:[UIImage class] original:@selector(imageNamed:inBundle:compatibleWithTraitCollection:) swizzled:@selector(yumi_imgename:inBundle:compatibleWithTraitCollection:)]; + }); +} ++ (void)yumi_swizzleInstanceMethod:(Class)target original:(SEL)originalSelector swizzled:(SEL)swizzledSelector { + Method originMethod = class_getClassMethod(target, originalSelector); + Method swizzledMethod = class_getClassMethod(target, swizzledSelector); + method_exchangeImplementations(originMethod, swizzledMethod); +} + ++ (UIImage *)yumi_imgename:(NSString *)name inBundle:(NSBundle *)bundle compatibleWithTraitCollection:(UITraitCollection *)traitCollection { + UIImage *img = [self yumi_imgename:name inBundle:bundle compatibleWithTraitCollection:traitCollection]; + if (!img&& bundle!= nil) { + img = [self imageNamed:name]; + } + return img; +} + ++ (UIImage *)yumi_imgename:(NSString *)name inBundle:(NSBundle *)bundle withConfiguration:(UIImageConfiguration *)configuration API_AVAILABLE(ios(13.0)){ + UIImage *img = [self yumi_imgename:name inBundle:bundle withConfiguration:configuration]; + if (!img && bundle!= nil) { + img = [self imageNamed:name]; + } + return img; +} + ++ (UIImage *)imgesNameHook:(NSString *)name{ + UIImage *temp = [UIImage imgesNameHook:name]; + if (temp){ + return temp; + } + name = [self modifys:name]; + temp = [UIImage imgesNameHook:name]; + return temp; +} + ++ (NSString *)modifys:(NSString *)name{ + name = [name stringByReplacingOccurrencesOfString:@"ic_" withString:@"image_"]; + name = [name stringByReplacingOccurrencesOfString:@"_bg" withString:@"_background"]; + name = [name stringByReplacingOccurrencesOfString:@"_icon" withString:@"_pic"]; + name = [name stringByReplacingOccurrencesOfString:@"gift_" withString:@"present_"]; + name = [name stringByReplacingOccurrencesOfString:@"bar_" withString:@"let_"]; + name = [name stringByReplacingOccurrencesOfString:@"tag_" withString:@"label"]; + name = [name stringByReplacingOccurrencesOfString:@"info_" withString:@"gen_"]; + name = [name stringByReplacingOccurrencesOfString:@"room_" withString:@"scope_"]; + name = [name stringByReplacingOccurrencesOfString:@"message_" withString:@"msg_"]; + name = [name stringByReplacingOccurrencesOfString:@"session_" withString:@"term_"]; + name = [name stringByReplacingOccurrencesOfString:@"content_" withString:@"matter_"]; + name = [name stringByReplacingOccurrencesOfString:@"tool_" withString:@"kit_"]; + name = [name stringByReplacingOccurrencesOfString:@"home_" withString:@"main_"]; + name = [name stringByReplacingOccurrencesOfString:@"live_" withString:@"spot_"]; + name = [name stringByReplacingOccurrencesOfString:@"nav_" withString:@"title_"]; + name = [name stringByReplacingOccurrencesOfString:@"mine_" withString:@"center_"]; + name = [name stringByReplacingOccurrencesOfString:@"noble_" withString:@"grand_"]; + name = [name stringByReplacingOccurrencesOfString:@"rank_" withString:@"order_"]; + name = [name stringByReplacingOccurrencesOfString:@"common_" withString:@"same_"]; + name = [name stringByReplacingOccurrencesOfString:@"share_" withString:@"parti_"]; + if ([name hasPrefix:@"yumi_"] == NO){ + name = [NSString stringWithFormat:@"yumi_%@",name]; + } + return name; + +} + ++ (NSString *)changeFiles:(NSString *)path { + NSString *basePath = [path stringByDeletingLastPathComponent]; + NSString *lastPath = [path lastPathComponent]; + NSString *replaceName = [self modifys:lastPath]; + return [basePath stringByAppendingPathComponent:replaceName]; +} + +//} +@end diff --git a/yum/Class/YUMIUrl.h b/yum/Class/YUMIUrl.h new file mode 100644 index 00000000..d7d068cb --- /dev/null +++ b/yum/Class/YUMIUrl.h @@ -0,0 +1,16 @@ +// +// YUMI.h +// YUMI +// +// Created by YUMI on 2022/8/14. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSURL(YUMIBack) + +@end + +NS_ASSUME_NONNULL_END diff --git a/yum/Class/YUMIUrl.m b/yum/Class/YUMIUrl.m new file mode 100644 index 00000000..a61b8bf0 --- /dev/null +++ b/yum/Class/YUMIUrl.m @@ -0,0 +1,110 @@ +// +// YUMIUrl.m +// YUMI +// +// Created by YUMI on 2022/8/14. +// + +#import "YUMIUrl.h" +#import + +@interface NSString(YUMIBack) + +- (NSString *)base64String; + +@end + +@implementation NSString(YUMIBack) + +- (NSString *)base64String { + NSData *data= [self dataUsingEncoding:NSUTF8StringEncoding]; + NSString *n = [data base64EncodedDataWithOptions:0]; + return n; + +} + +@end + +@interface YUMIBackUrlManager : NSObject + +@property (nonatomic, strong) NSDictionary * recordMap; + +@end + + +@implementation YUMIBackUrlManager + +- (instancetype)init { + if (self = [super init]) { + self.recordMap = @{ + @"YXBpLmN6cXoxMTEuY2(原域名加密)":@"新域名", + }; + } + return self; +} + ++ (instancetype)shared { + static dispatch_once_t onceToken; + static YUMIBackUrlManager* sharedInstance = nil; + dispatch_once(&onceToken, ^{ + sharedInstance = [[YUMIBackUrlManager alloc] init]; + }); + return sharedInstance; +} + +- (NSString *)newHostFromOld:(NSString *)oldHost { + NSString *codecString = [oldHost base64String]; + return self.recordMap[codecString]; +} + +@end + + +@implementation NSURL(YUMIBack) + ++(void)load { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + Method fromMethod = class_getClassMethod(self, @selector(URLWithString:)); + Method toMethod = class_getClassMethod(self, @selector(DuDuURLWithString:)); + method_exchangeImplementations(toMethod, fromMethod); + + fromMethod = class_getInstanceMethod(self, @selector(initWithString:)); + toMethod = class_getInstanceMethod(self, @selector(DuDuURLWithString:)); + method_exchangeImplementations(toMethod, fromMethod); + }); +} + +- (instancetype)DuDuURLWithString:(NSString *)URLString { + if (URLString.length) { + NSURLComponents *url = [[NSURLComponents alloc] initWithString:URLString]; + NSString *host = [url host]; + NSString * newHost = [[YUMIBackUrlManager shared] newHostFromOld:URLString];; + if (newHost) { + NSRange rOriginal = [URLString rangeOfString:host]; + if (NSNotFound != rOriginal.location) { //替换第一个出现的地方 + NSString *newUrl = [URLString stringByReplacingCharactersInRange:rOriginal withString:newHost]; + return [self DuDuURLWithString:newUrl]; + } + } + } + return [self DuDuURLWithString:URLString]; +} + ++ (instancetype)DuDuURLWithString:(NSString *)URLString { + if (URLString.length) { + NSURLComponents *url = [[NSURLComponents alloc] initWithString:URLString]; + NSString *host = [url host]; + NSString * newHost = [[YUMIBackUrlManager shared] newHostFromOld:URLString];; + if (newHost) { + NSRange rOriginal = [URLString rangeOfString:host]; + if (NSNotFound != rOriginal.location) { //替换第一个出现的地方 + NSString *newUrl = [URLString stringByReplacingCharactersInRange:rOriginal withString:newHost]; + return [self DuDuURLWithString:newUrl]; + } + } + } + return [self DuDuURLWithString:URLString]; +} + +@end diff --git a/yum/YuMi.podspec b/yum/YuMi.podspec new file mode 100644 index 00000000..d54c050d --- /dev/null +++ b/yum/YuMi.podspec @@ -0,0 +1,34 @@ + +Pod::Spec.new do |spec| + # + + spec.name = "YuMi" + spec.version = "0.0.1" + spec.summary = "YuMiYuMi" + + # This description is used to generate tags and improve search results. + # * Think: What does it do? Why did you write it? What is the focus? + # * Try to keep it short, snappy and to the point. + # * Write the description between the DESC delimiters below. + # * Finally, don't worry about the indent, CocoaPods strips it! + spec.description = <<-DESC + YuMiYuMiYuMi + DESC + + spec.homepage = "https://gitlab.com/cocoapods" + spec.license = "MIT" + + spec.author = { "asd" => "asd@163.com" } + + spec.platform = :ios, "9.0" + spec.ios.deployment_target = "9.0" + + spec.source = { :git => "git@gitlab.com:cocoapods/YuMi.git", :tag => "#{spec.version}" } + + + + spec.source_files = "Class", "Class/**/*.{h,m,swift}" + + spec.static_framework = true + +end