UKAppDelegateMoudle 0.1.0

UKAppDelegateMoudle 0.1.0

chardxu 维护。



  • 作者:
  • chardxu

三方库和 AppDelegate 交互封装

例子

// AppDelegate
import UKAppDelegateMoudle

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    override init() {
        AppDelegate.setuAppHandler()
        super.init()
    }
    
    class func setuAppHandler() {
        UKHandlerFactory.register(handler: UKAppDelegateHandler.shared, protocol: UKAppDelegateProtocol.self)
        UKAppDelegateHandler.shared.setUp(thirdLib: UKJiguangHandler())
    }
    
    static let appDelegateHandler: UKAppDelegateProtocol = {
        let handler = UKHandlerFactory.handler(for: UKAppDelegateProtocol.self) as! UKAppDelegateProtocol
        return handler
    }()
    

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
        return AppDelegate.appDelegateHandler.application?(application, didFinishLaunchingWithOptions: launchOptions) ?? true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        AppDelegate.appDelegateHandler.applicationWillResignActive?(application)
    }
}
// Handler
import UKAppDelegateMoudle

class UKJiguangHandler: NSObject, UKAppDelegateProtocol {
    func syncMainApplication(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
        initJiguangSync()
    }

    func asyncMainApplication(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
        initJiguangAsync()
    }
}

// UKAppDelegateProtocol
extension UKJiguangHandler {
    

}

// AppDelegate
extension UKJiguangHandler {
    func applicationWillResignActive(_ application: UIApplication) {
        print("")
    }
}

要求

安装

UKAppDelegateMoudle 可通过 CocoaPods 获得。要安装它,只需在您的 Podfile 中添加以下行:

pod 'UKAppDelegateMoudle'

作者

chardxu, [email protected]

许可证

UKAppDelegateMoudle基于MIT许可证提供。更多信息请参阅LICENSE文件。