Solution a:FRDModuleManager

The FRDModuleManager provides a unified interface for modules to know the application life cycle. Leave hooks in the AppDelegate that call the corresponding methods of the module during a particular lifecycle. This will make the AppDelegate simpler. Use of the application lifecycle is also clearer. evernotecid://6F55E44D-BBC1-43F1-9310-4138A0D19764/appyinxiangcom/11652118/ENResource/p18418

Use: ReferencegithubThe document

Advantages:

  • 1. Simple, just a few lines of code.
  • Each module that is added can “enjoy” the life cycle of the AppDelegate.

Disadvantages:

  • 1. Each module needs to be initialized and allocated memory. When a large number of modules are registered in the FRDModuleManager, a large number of objects will be created and App startup speed will be affected.
  • 2. Lack of module initialization priority. When there are three modules A,B, and C,C depends on B, and B depends on A.

The second disadvantage can be avoided by adjusting the order of classes in the plist file to implement the order in which modules are called. Let’s verify this with the PList file in the FRDModuleManager demo.

Sequence 1: FRDGroupModule is on top

Sequence 2: FRDGroupModule is in the following sequence

Scheme 2:JSDecoupledAppDelegate

Jsgoldman is a lightweight AppDelegate decoupling tool developed by the authors of JSBadgeView. It separates the AppDelegate function points from each other and assigns control via a proxy. Implementation principle, using objective-C message forwarding mechanism, forwarding each method of the AppDelegate to achieve the decoupling of the AppDelegate

Use: ReferencegithubThe document

Advantages:

  • (1) JSgoldman’s own breakdown of AppDelegates’ functions is helpful in understanding that Appdelegates do host too many functions.
  • 2. Since the execution order of each sub-proxy object is determined, the problem of interdependence in FRDModuleManager can be basically solved.

Disadvantages:

(S) The drawbacks of JSgoldman Delegate are obvious: To use it, we must discard the native AppDelegate, so we can’t get the window through ((AppDelegate *)[UIApplication sharedApplication].delegate).window, And the Windows rootViewController.

Scheme 3: AppDelegate Category (Category)

Advantages:

Without adding any third party libraries, we can add many methods to the AppDelegate and easily control the order in which the methods are executed

Disadvantages:

Adding new attributes is cumbersome and can only be implemented through third-party libraries such as Runtime or BlocksKit

Reference: DelegateDietDemo