From 5ba1356d44c5bcb39a6179bf476720ff9ae4f068 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Wed, 14 Nov 2018 11:25:58 -0800 Subject: [PATCH] Added delegate forwarding for didReceiveLocalNotification and willPresentNotification --- .../ios/framework/Headers/FlutterPlugin.h | 16 ++++++++++ .../FlutterPluginAppLifeCycleDelegate.h | 15 ++++++++++ .../framework/Source/FlutterAppDelegate.mm | 17 +++++++++++ .../FlutterPluginAppLifeCycleDelegate.mm | 30 +++++++++++++++++++ 4 files changed, 78 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index e76416b9fbcd5..bc6997f48b2be 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -6,6 +6,7 @@ #define FLUTTER_FLUTTERPLUGIN_H_ #import +#import #include "FlutterBinaryMessenger.h" #include "FlutterChannels.h" @@ -116,6 +117,21 @@ NS_ASSUME_NONNULL_BEGIN didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler; +/** + * Calls all plugins registered for `UIApplicationDelegate` callbacks. + */ +- (void)application:(UIApplication*)application + didReceiveLocalNotification:(UILocalNotification*)notification; + +/** + * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. + */ +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + willPresentNotification:(UNNotification*)notification + withCompletionHandler: + (void (^)(UNNotificationPresentationOptions options))completionHandler + API_AVAILABLE(ios(10)); + /** * Called if this plugin has been registered for `UIApplicationDelegate` callbacks. * diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h index 36ba12ef2f5d8..a8dda282b56fd 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h @@ -85,6 +85,21 @@ FLUTTER_EXPORT didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler; +/** + * Calls all plugins registered for `UIApplicationDelegate` callbacks. + */ +- (void)application:(UIApplication*)application + didReceiveLocalNotification:(UILocalNotification*)notification; + +/** + * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. + */ +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + willPresentNotification:(UNNotification*)notification + withCompletionHandler: + (void (^)(UNNotificationPresentationOptions options))completionHandler + API_AVAILABLE(ios(10)); + /** * Calls all plugins registered for `UIApplicationDelegate` callbacks in order of registration until * some plugin handles the request. diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 37f0c9e006c2d..f3f1786e4555a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -94,6 +94,23 @@ - (void)application:(UIApplication*)application fetchCompletionHandler:completionHandler]; } +- (void)application:(UIApplication*)application + didReceiveLocalNotification:(UILocalNotification*)notification { + [_lifeCycleDelegate application:application didReceiveLocalNotification:notification]; +} + +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + willPresentNotification:(UNNotification*)notification + withCompletionHandler: + (void (^)(UNNotificationPresentationOptions options))completionHandler + API_AVAILABLE(ios(10)) { + if (@available(iOS 10.0, *)) { + [_lifeCycleDelegate userNotificationCenter:center + willPresentNotification:notification + withCompletionHandler:completionHandler]; + } +} + - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url options:(NSDictionary*)options { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm index f262d300f4332..70b54b0f29231 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -202,6 +202,36 @@ - (void)application:(UIApplication*)application } } +- (void)application:(UIApplication*)application + didReceiveLocalNotification:(UILocalNotification*)notification { + for (id plugin in _pluginDelegates) { + if (!plugin) { + continue; + } + if ([plugin respondsToSelector:_cmd]) { + [plugin application:application didReceiveLocalNotification:notification]; + } + } +} + +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + willPresentNotification:(UNNotification*)notification + withCompletionHandler: + (void (^)(UNNotificationPresentationOptions options))completionHandler { + if (@available(iOS 10.0, *)) { + for (id plugin in _pluginDelegates) { + if (!plugin) { + continue; + } + if ([plugin respondsToSelector:_cmd]) { + [plugin userNotificationCenter:center + willPresentNotification:notification + withCompletionHandler:completionHandler]; + } + } + } +} + - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url options:(NSDictionary*)options {