概述
基本構(gòu)成:Target_XX、CTMediator、CTMediator_XX分類,XX為模塊名稱,可以用static字符串來保存
CTMediator接口分析
+ (instancetype _Nonnull)sharedInstance;
// 遠程App調(diào)用入口
- (id _Nullable)performActionWithUrl:(NSURL * _Nullable)url completion:(void(^_Nullable)(NSDictionary * _Nullable info))completion;
// 本地組件調(diào)用入口
- (id _Nullable )performTarget:(NSString * _Nullable)targetName action:(NSString * _Nullable)actionName params:(NSDictionary * _Nullable)params shouldCacheTarget:(BOOL)shouldCacheTarget;
- (void)releaseCachedTargetWithTargetName:(NSString *_Nullable)targetName;
調(diào)用流程
1.添加XX模塊的的CTMediator分類,定義接口,接口內(nèi)部通過運行時動態(tài)生成target的實例,采用performSelector的方式動態(tài)調(diào)用target對應(yīng)的action,如果不存在則調(diào)用target的notFound方法,如果還沒找到則使用默認的noTarget 方法,防止崩潰。