Swiftpack.co - FengDeng/AppDelegateHooks as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by FengDeng.
FengDeng/AppDelegateHooks 0.0.1
Hook AppDelegate methods ,distributed your UIApplicationDelegate code to every component.
⭐️ 22
🕓 4 years ago
.package(url: "https://github.com/FengDeng/AppDelegateHooks.git", from: "0.0.1")

AppDelegateHooks

CocoaPods Compatible Carthage Compatible Platform

AppDelegateHooks: easy library to hook AppDelegate methods ,distributed your UIApplicationDelegate code in every component.

Features

  • ☑ Native UIApplicationDelegate code prompt
  • ☑ Just new class inhert AppDelegateHook
  • ☑ Rewrite level property,Custom calling sequence
  • ☑ 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所有回调的轻量级的库,把你的初始化代码分散到各个组件内部。

特性

  • ☑ 原生的UIApplicationDelegate代码提示
  • ☑ 新建Class,继承AppDelegateHook即可,无需其他操作
  • ☑ 提供重写level,自定义调用优先级
  • ☑ 组件内,模块内,无限制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

GitHub

link
Stars: 22
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics