美文网首页
JSDecoupledAppDelegate简介

JSDecoupledAppDelegate简介

作者: Maggie的小蜗居 | 来源:发表于2017-03-29 14:14 被阅读111次

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];
}

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

相关文章

  • JSDecoupledAppDelegate简介

    JSDecoupledAppDelegate JSDecoupledAppDelegate目的是将AppDeleg...

  • 18旅游二班各组自我简介汇总

    一组简介 二组简介 三组简介 四组简介 五组简介 六组简介 七组简介 八组简介

  • 简介

    上辈子,洛幽喜欢了东凡一辈子,没有结果,之后她死了,她不后悔,只是为什么她一睁眼,嗯?捏了捏自己的脸,她这是回到了...

  • 简介

    1.主动地去阅读。 2.阅读目的:获得资讯,获得理解 前者为了增进资讯,获得信息,不能增加理解力。后者为了理解更多...

  • 简介

    姓名:赵金星 电话:13903984903 坐标:河南三门峡市陕州区。 三个标签的自我介绍: 1.时间管理践行者 ...

  • 简介

    朱凝不过打错个字,便被天打雷劈回古代。 为毛别人穿个废柴嫡女,她穿个废柴庶女?地位更低了哎 哇喔,别人嫁王爷,她嫁...

  • 简介

    凌波网络考试系统,是一套运行于Windows系统之上的无纸化网络考试软件。包括试卷编辑、分发试卷、学生答卷、自动阅...

  • 简介

    名字:笨小孩 不是富二代的笨小孩为了生活选择了编程。在大多数人眼里可能感觉编程是很无聊很辛苦经常加班的事情,其实人...

  • 简介

    A Native Client web application consists of JavaScript, H...

  • 简介

    选择django作为毕设项目,和日后工作内容。故在简单得做了一个blog和毕设系统之间,想深入了解django,会...

网友评论

      本文标题:JSDecoupledAppDelegate简介

      本文链接:https://www.haomeiwen.com/subject/usweottx.html