AppDelegateHooks
Hook AppDelegate methods ,distributed your UIApplicationDelegate code to every component.
Install / Use
/learn @FengDeng/AppDelegateHooksREADME
AppDelegateHooks
AppDelegateHooks: easy library to hook AppDelegate methods ,distributed your UIApplicationDelegate code in every component.
Features
- [x] Native UIApplicationDelegate code prompt
- [x] Just new class inhert AppDelegateHook
- [x] Rewrite level property,Custom calling sequence
- [x] Hooks everywhere
Installation
Cocoapods
pod 'AppDelegateHooks', '~> 0.0.1'
Carthage
github "FengDeng/AppDelegateHooks" ~> 0.0.1
~~SPM~~
dependencies: [
.package(url: "https://github.com/FengDeng/AppDelegateHooks", from: "0.0.1")
]
Usage
sample in main project:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print("Main didFinishLaunchingWithOptions")
return true
}
}
in your workspace or framework:
class ExampleHook1 : AppDelegateHook{
//添加你想要的生命周期
self.level = 1000//如果你这个组件想要最先加载 level越大越先
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
print("ExampleHook1 didFinishLaunchingWithOptions")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
print("ExampleHook1 applicationWillResignActive")
}
......
}
class ExampleHook2 : AppDelegateHook{
//添加你想要的生命周期
self.level = 10000//如果你这个组件想要最先加载 level越大越先
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
print("ExampleHook2 didFinishLaunchingWithOptions")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
print("ExampleHook2 applicationWillResignActive")
}
......
}
print:
ExampleHook2 didFinishLaunchingWithOptions
ExampleHook1 didFinishLaunchingWithOptions
Main didFinishLaunchingWithOptions
ExampleHook2 applicationWillResignActive
ExampleHook1 applicationWillResignActive
Thanks
Thanks for Aspects which developed by @steipete in GitHub
中文
AppDelegateHooks: 一个可以轻松拦截AppDelegate所有回调的轻量级的库,把你的初始化代码分散到各个组件内部。
特性
- [x] 原生的UIApplicationDelegate代码提示
- [x] 新建Class,继承AppDelegateHook即可,无需其他操作
- [x] 提供重写level,自定义调用优先级
- [x] 组件内,模块内,无限制hook主工程生命周期
安装
Cocoapods
pod 'AppDelegateHooks', '~> 0.0.1'
Carthage
github "FengDeng/AppDelegateHooks" ~> 0.0.1
~~SPM~~
dependencies: [
.package(url: "https://github.com/FengDeng/AppDelegateHooks", from: "0.0.1")
]
使用
在子组件或者模块内新建文件
class ExampleHook1 : AppDelegateHook{
//添加你想要的生命周期
self.level = 1000//如果你这个组件想要最先加载 level越大越先
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
print("ExampleHook1 didFinishLaunchingWithOptions")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
print("ExampleHook1 applicationWillResignActive")
}
......
}
class ExampleHook2 : AppDelegateHook{
//添加你想要的生命周期
self.level = 10000//如果你这个组件想要最先加载 level越大越先
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
print("ExampleHook2 didFinishLaunchingWithOptions")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
print("ExampleHook2 applicationWillResignActive")
}
......
}
打印如下:
ExampleHook2 didFinishLaunchingWithOptions
ExampleHook1 didFinishLaunchingWithOptions
Main didFinishLaunchingWithOptions
ExampleHook2 applicationWillResignActive
ExampleHook1 applicationWillResignActive
