Latest 1.0.5
Homepage https://github.com/JeryHuo/JRHModuleManager
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit

简介

AppDelegate瘦身方案Swift版本,需要先提前注册需要瘦身的模块,然后在AppDelegate中的代理方法中调用一个中间件JRHModuleManagerJRHModuleManager负责集中分发给已经注册并且实现协议的模块。

CocoaPods导入

pod 'JRHModuleManager', '~> 1.0.5'

使用

AppDelegate.swift文件中的didFinishLaunchingWithOptions方法中注册模块,只需要注册一次

tips

可以创建plist文件来管理需要注册的模块,以便方便维护

调用

// 1. 先提前注册模块,只需要注册一次
let plistPath = Bundle.main.path(forResource: "JRHModuleManager", ofType: "plist")!
JRHModuleManager.shareInstance().loadModulesWithPlistFile(filePath: plistPath)

// 2. 在App启动的时候调用模块
let res = JRHModuleManager.shareInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

同样的道理,可以给AppDelegate的任何方法进行瘦身

/// 进入后台/退出程序
func applicationDidEnterBackground(_ application: UIApplication) {
    let res = JRHModuleManager.shareInstance().applicationDidEnterBackground(application)
    return res
}

/// 从后台回来点击进入应用
func applicationWillEnterForeground(_ application: UIApplication) {
    JRHModuleManager.shareInstance().applicationWillEnterForeground(application)
}

/// 关闭程序
func applicationWillTerminate(_ application: UIApplication) {
    JRHModuleManager.shareInstance().applicationWillTerminate(application)
}

最后在具体的类中去操作,也之前已经注册好的的模块类中去操作,假设我们有一个已经注册了的AppTimeLineModule.swift的模块, 那么就在此类中实现相应需要处理的方法

/// App启动
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    print("didFinishLaunchingWithOptions")
    // code ...
    return true
}

/// 进入后台/退出程序    
func applicationDidEnterBackground(_ application: UIApplication) {
    print("applicationDidEnterBackground")
    // code ...
}

/// 从后台回来点击进入应用   
func applicationWillEnterForeground(_ application: UIApplication) {
    print("applicationWillEnterForeground")
    // code ...
}

/// 关闭程序  
func applicationWillTerminate(_ application: UIApplication) {
    print("applicationWillTerminate")
    // code ...
}

Latest podspec

{
    "name": "JRHModuleManager",
    "version": "1.0.5",
    "summary": "AppDelegateu7626u8eabu65b9u6848",
    "homepage": "https://github.com/JeryHuo/JRHModuleManager",
    "license": "MIT",
    "authors": "JeryHuo",
    "social_media_url": "https://github.com/JeryHuo",
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.0",
    "source": {
        "git": "https://github.com/JeryHuo/JRHModuleManager.git",
        "tag": "1.0.5"
    },
    "source_files": "JRHModuleManager/**/*.{swift}",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This