JSDecoupledAppDelegate简介

JSDecoupledAppDelegate

JSDecoupledAppDelegate目的是将AppDelegate解耦

首先需要将main.m里的AppDelegate 替换成JSDecoupledAppDelegate
JSDecoupledAppDelegate 也继承了UIResponder,遵循了UIApplicationDelegate
JSDecoupledAppDelegate将UIApplicationDelegate拆分成不同的Delegate

@protocol JSApplicationStateDelegate;
@protocol JSApplicationDefaultOrientationDelegate;
@protocol JSApplicationBackgroundFetchDelegate;
@protocol JSApplicationRemoteNotificationsDelegate;
@protocol JSApplicationLocalNotificationsDelegate;
@protocol JSApplicationStateRestorationDelegate;
@protocol JSApplicationURLResourceOpeningDelegate;
@protocol JSApplicationShortcutItemDelegate;
@protocol JSApplicationHealthDelegate;
@protocol JSApplicationProtectedDataDelegate;
@protocol JSApplicationWatchInteractionDelegate;
@protocol JSApplicationExtensionDelegate;
@protocol JSApplicationActivityContinuationDelegate;

针对每个delegate都有对应的属性

@property (strong, nonatomic, nullable) id<JSApplicationStateDelegate> appStateDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationDefaultOrientationDelegate> appDefaultOrientationDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationBackgroundFetchDelegate> backgroundFetchDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationRemoteNotificationsDelegate> remoteNotificationsDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationLocalNotificationsDelegate> localNotificationsDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationStateRestorationDelegate> stateRestorationDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationURLResourceOpeningDelegate> URLResourceOpeningDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationShortcutItemDelegate> shortcutItemDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationHealthDelegate> healthDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationProtectedDataDelegate> protectedDataDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationWatchInteractionDelegate> watchInteractionDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationExtensionDelegate> extensionDelegate;
@property (strong, nonatomic, nullable) id<JSApplicationActivityContinuationDelegate> activityContinuationDelegate;

当需要处理app状态相关的操作时,只要新建一个对象,并遵循JSApplicationStateDelegate协议
在对象的load方法里将该delegate要实现的对象指派给新建的对象

@interface AppDelegate : UIResponder<JSApplicationStateDelegate>

@end

+ (void)load
{
    [JSDecoupledAppDelegate sharedAppDelegate].appStateDelegate = [self new];
}

这样就能实现解耦,不同的事件使用新建不同对象遵循不同的协议

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,392评论 30 472
  • 1.OC里用到集合类是什么? 基本类型为:NSArray,NSSet以及NSDictionary 可变类型为:NS...
    轻皱眉头浅忧思阅读 5,231评论 0 3
  • 最近一朋友正准备跳槽,就从各处搜索整理一些基础,便于朋友复习,也便于自己复习查看. 1. 回答person的ret...
    smile丽语阅读 5,791评论 0 7
  • 1.属性readwrite,readonly,assign,retain,copy,nonatomic 各是什么作...
    曾令伟阅读 4,700评论 0 10
  • 反射——Java高级开发必须懂的1 类实际上都是java.lang.class的实例对象。Class类实例的表示:...
    苏筱筑阅读 2,312评论 0 0

友情链接更多精彩内容