diff --git a/.gitignore b/.gitignore index 312d1f6..42b4389 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots/**/*.png fastlane/test_output +.DS_Store diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index c7f6bae..898d9d9 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -19,9 +19,11 @@ class AppDelegate: PluggableApplicationDelegate { LoggerApplicationService() ] } +} - override init() { - super.init() +extension AppDelegate { + override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { self.window = UIWindow(frame: UIScreen.main.bounds) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } diff --git a/Sources/AppServicesManager+UNUserNotification.swift b/Sources/AppServicesManager+UNUserNotification.swift index ef12feb..2b2576f 100644 --- a/Sources/AppServicesManager+UNUserNotification.swift +++ b/Sources/AppServicesManager+UNUserNotification.swift @@ -13,16 +13,30 @@ extension PluggableApplicationDelegate: UNUserNotificationCenterDelegate { @available(iOS 10.0, *) public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { - for service in _services { - service.userNotificationCenter?(center, willPresent: notification, withCompletionHandler: completionHandler) - } + apply({ (service, completion) -> Void? in + service.userNotificationCenter?( + center, + willPresent: notification, + withCompletionHandler: { opt in + completion(opt) + }) + }, completionHandler: { options in + completionHandler(UNNotificationPresentationOptions(options)) + }) } @available(iOS 10.0, *) public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { - for service in _services { - service.userNotificationCenter?(center, didReceive: response, withCompletionHandler: completionHandler) - } + apply({ (service, completion) -> Void? in + service.userNotificationCenter?( + center, + didReceive: response, + withCompletionHandler: { + completion(()) + }) + }, completionHandler: { _ in + completionHandler() + }) } diff --git a/Sources/AppServicesManager.swift b/Sources/AppServicesManager.swift index fd2b21d..58378f0 100644 --- a/Sources/AppServicesManager.swift +++ b/Sources/AppServicesManager.swift @@ -29,6 +29,30 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate { lazy var _services: [ApplicationService] = { return self.services }() + + lazy var _methodRespondsCache: [String: Bool] = { + print(NSDate()) + func generateProtocolMethods(_ protocol: Protocol, methodPrifix: String) -> [String] { + var count: UInt32 = 0 + guard let list = protocol_copyMethodDescriptionList(`protocol`, false, true, &count) else { return [] } + return (0..(_ work: (ApplicationService, @escaping (T) -> Void) -> S?, completionHandler: @escaping ([T]) -> Void) -> [S] { @@ -55,4 +79,12 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate { return returns } + + override open func responds(to aSelector: Selector!) -> Bool { + if let isHaveServicesResponds = _methodRespondsCache[NSStringFromSelector(aSelector)] { + return isHaveServicesResponds + } else { + return super.responds(to: aSelector) + } + } }