diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 95ec3adb2d6fb..8092217fcfe35 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -23,6 +23,9 @@ NS_ASSUME_NONNULL_BEGIN * Protocol for listener of events from the UIApplication, typically a FlutterPlugin. */ @protocol FlutterApplicationLifeCycleDelegate +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 + +#endif @optional /** * Called if this has been registered for `UIApplicationDelegate` callbacks. @@ -98,15 +101,6 @@ NS_ASSUME_NONNULL_BEGIN "See -[UIApplicationDelegate application:didReceiveLocalNotification:] deprecation", ios(4.0, 10.0)); -/** - * 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 has been registered for `UIApplicationDelegate` callbacks. * @@ -372,8 +366,14 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject* /*************************************************************************************************** * Implement this in the `UIAppDelegate` of your app to enable Flutter plugins to register * themselves to the application life cycle events. + * + * For plugins to receive events from `UNUserNotificationCenter`, register this as the + * `UNUserNotificationCenterDelegate`. */ @protocol FlutterAppLifeCycleProvider +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 + +#endif - (void)addApplicationLifeCycleDelegate:(NSObject*)delegate; @end diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h index f69cbd2ea2d3f..95a4f233409d9 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h @@ -14,6 +14,9 @@ NS_ASSUME_NONNULL_BEGIN */ FLUTTER_EXPORT @interface FlutterPluginAppLifeCycleDelegate : NSObject +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 + +#endif /** * Registers `delegate` to receive life cycle callbacks via this FlutterPluginAppLifecycleDelegate @@ -70,15 +73,6 @@ FLUTTER_EXPORT "See -[UIApplicationDelegate application:didReceiveLocalNotification:] deprecation", ios(4.0, 10.0)); -/** - * 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 70f856ba7705a..28a4a153e2cc1 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -83,15 +83,27 @@ - (void)application:(UIApplication*)application - (void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler: - (void (^)(UNNotificationPresentationOptions options))completionHandler - API_AVAILABLE(ios(10)) { - if (@available(iOS 10.0, *)) { + (void (^)(UNNotificationPresentationOptions options))completionHandler { + if ([_lifeCycleDelegate respondsToSelector:_cmd]) { [_lifeCycleDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; } } +/** + * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. + */ +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + didReceiveNotificationResponse:(UNNotificationResponse*)response + withCompletionHandler:(void (^)(void))completionHandler { + if ([_lifeCycleDelegate respondsToSelector:_cmd]) { + [_lifeCycleDelegate userNotificationCenter:center + didReceiveNotificationResponse:response + 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 b0ab5b5a849b8..677dac7bfc012 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -276,16 +276,23 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler: (void (^)(UNNotificationPresentationOptions options))completionHandler { - if (@available(iOS 10.0, *)) { - for (NSObject* delegate in _delegates) { - if (!delegate) { - continue; - } - if ([delegate respondsToSelector:_cmd]) { - [delegate userNotificationCenter:center - willPresentNotification:notification + for (NSObject* delegate in _delegates) { + if ([delegate respondsToSelector:_cmd]) { + [delegate userNotificationCenter:center + willPresentNotification:notification + withCompletionHandler:completionHandler]; + } + } +} + +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + didReceiveNotificationResponse:(UNNotificationResponse*)response + withCompletionHandler:(void (^)(void))completionHandler { + for (id delegate in _delegates) { + if ([delegate respondsToSelector:_cmd]) { + [delegate userNotificationCenter:center + didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; - } } } }