解耦方案是针对AppDelegate,通过消息的转发、GCDMulticastDelegate代理的一对多模式来实现解耦。以下是核心代码:
消息转发:
+ (BOOL)resolveInstanceMethod:(SEL)sel{
return NO;
}
- (id)forwardingTargetForSelector:(SEL)aSelector{
if([selfrespondsToSelector:aSelector]) {
return self;
}
return self.multicastDelegate;
}
添加delegate:
- (void)addImplementationArray:(NSArray *)targets
queue:(dispatch_queue_t)queue;
- (void)addImplementationQueueTarget:(id)target
queue:(dispatch_queue_t)queue
需要使用AppDelegate方法的类,需要实现UIApplicationDelegate协议。