From 88e391c749db741eee5650ac7b52b83363507b26 Mon Sep 17 00:00:00 2001 From: kagen Date: Mon, 18 Nov 2019 13:40:30 +0800 Subject: [PATCH 1/4] Fix warning UIWindows were created prior to initial application activation. This may result in incorrect visual appearance. --- Example/AppDelegate.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) } } From c96afe6b145ce1bcd2ae09d036d4e27dc286aa03 Mon Sep 17 00:00:00 2001 From: kagen Date: Mon, 18 Nov 2019 13:40:41 +0800 Subject: [PATCH 2/4] Fix UserNotifications delegate methods implementation --- ...ppServicesManager+UNUserNotification.swift | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) 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() + }) } From 050eddb0e553d3c1409c4ab920449364cca41db6 Mon Sep 17 00:00:00 2001 From: kagen Date: Mon, 18 Nov 2019 13:40:49 +0800 Subject: [PATCH 3/4] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From 6ae086dec32cd9bdd4b5d0e5e910282ca65da5d6 Mon Sep 17 00:00:00 2001 From: kagen Date: Mon, 18 Nov 2019 13:41:00 +0800 Subject: [PATCH 4/4] Fix: Responds to selector when services has Implement delegate method --- Sources/AppServicesManager.swift | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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) + } + } }