From d48d4a2a1246a802d9e09304a634914d135fcc53 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Jul 2019 13:34:21 -0700 Subject: [PATCH 01/23] Add other UNUserNotificationDelegate method and register as delegate --- .../ios/framework/Headers/FlutterPlugin.h | 8 ++++++++ .../FlutterPluginAppLifeCycleDelegate.h | 8 ++++++++ .../framework/Source/FlutterAppDelegate.mm | 14 ++++++++++++++ .../FlutterPluginAppLifeCycleDelegate.mm | 19 +++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 8d63dbc02caad..b1fbf1c0e8f80 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -159,6 +159,14 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject* (void (^)(UNNotificationPresentationOptions options))completionHandler API_AVAILABLE(ios(10)); +/** + * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. + */ +- (void)userNotificationCenter:(UNUserNotificationCenter *)center + didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)(void))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 b791d907a59f5..b21684440aff2 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h @@ -104,6 +104,14 @@ FLUTTER_EXPORT (void (^)(UNNotificationPresentationOptions options))completionHandler API_AVAILABLE(ios(10)); +/** + * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. + */ +- (void)userNotificationCenter:(UNUserNotificationCenter *)center + didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)(void))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 b918437cf6f69..8850e922c5802 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -112,6 +112,20 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center } } +/** + * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. + */ +- (void)userNotificationCenter:(UNUserNotificationCenter *)center + didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)(void))completionHandler + API_AVAILABLE(ios(10)) { + if (@available(iOS 10.0, *)) { + [_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 37016945dfd8d..385a0739c0d90 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -261,6 +261,25 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center } } +- (void)userNotificationCenter:(UNUserNotificationCenter *)center + didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)(void))completionHandler + API_AVAILABLE(ios(10)) { + if (@available(iOS 10.0, *)) { + for (id plugin in _pluginDelegates) { + if (!plugin) { + continue; + } + if ([plugin respondsToSelector:_cmd]) { + [plugin userNotificationCenter:center + didReceiveNotificationResponse:response + withCompletionHandler:completionHandler]; + + } + } + } +} + - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url options:(NSDictionary*)options { From a42883a4ac715aa842fd2782815b9227a38695be Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Jul 2019 17:17:57 -0700 Subject: [PATCH 02/23] Add UNUserNotificationDelegate to receive delegate calls --- .../darwin/ios/framework/Headers/FlutterAppDelegate.h | 2 +- .../platform/darwin/ios/framework/Headers/FlutterPlugin.h | 6 ++++++ .../darwin/ios/framework/Source/FlutterAppDelegate.mm | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 8684a22ea7733..53416c0342c21 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -25,7 +25,7 @@ */ FLUTTER_EXPORT @interface FlutterAppDelegate - : UIResponder + : UIResponder @property(strong, nonatomic) UIWindow* window; diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index b1fbf1c0e8f80..4ec092cfe450b 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -371,6 +371,12 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject* */ @protocol FlutterAppLifeCycleProvider - (void)addApplicationLifeCycleDelegate:(NSObject*)delegate; + +/** + * Implement this in the `UIAppDelegate` of your app to enable Flutter plugins to receive + * calls as `UNUserNotificationCenterDelegate` when they are added to `addApplicationLifeCycleDelegate`. + */ +- (void)registerAsUserNotificationCenterDelegate; @end NS_ASSUME_NONNULL_END; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 8850e922c5802..e0c4b572ec60d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -211,6 +211,14 @@ - (void)addApplicationLifeCycleDelegate:(NSObject*)delegate { [_lifeCycleDelegate addDelegate:delegate]; } +- (void)registerAsUserNotificationCenterDelegate { + if ([UNUserNotificationCenter class] != nil) { + // iOS 10 or later + // For iOS 10 display notification (sent via APNS) + [UNUserNotificationCenter currentNotificationCenter].delegate = self; + } +} + #pragma mark - UIApplicationDelegate method dynamic implementation - (BOOL)respondsToSelector:(SEL)selector { From a5a3ac31c8fdd28fa24ead8675ced312fc24c01f Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Jul 2019 18:01:36 -0700 Subject: [PATCH 03/23] format FlutterAppDelegate.h --- .../darwin/ios/framework/Headers/FlutterAppDelegate.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 53416c0342c21..170bf31b7419a 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -25,7 +25,10 @@ */ FLUTTER_EXPORT @interface FlutterAppDelegate - : UIResponder + : UIResponder @property(strong, nonatomic) UIWindow* window; From 151293c929320277be53d1065f5c0a5d98a34574 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Jul 2019 18:04:49 -0700 Subject: [PATCH 04/23] format FlutterPlugin.h --- .../darwin/ios/framework/Headers/FlutterPlugin.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 4ec092cfe450b..ababbac20c1b0 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -162,10 +162,9 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject* /** * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. */ -- (void)userNotificationCenter:(UNUserNotificationCenter *)center - didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void (^)(void))completionHandler - API_AVAILABLE(ios(10)); +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + didReceiveNotificationResponse:(UNNotificationResponse*)response + withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10)); /** * Called if this plugin has been registered for `UIApplicationDelegate` callbacks. @@ -374,7 +373,8 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject* /** * Implement this in the `UIAppDelegate` of your app to enable Flutter plugins to receive - * calls as `UNUserNotificationCenterDelegate` when they are added to `addApplicationLifeCycleDelegate`. + * calls as `UNUserNotificationCenterDelegate` when they are added to + * `addApplicationLifeCycleDelegate`. */ - (void)registerAsUserNotificationCenterDelegate; @end From ccc9b6479e0210f1be0ca560d62b95403d08fff8 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Jul 2019 18:06:50 -0700 Subject: [PATCH 05/23] format FormatAppDelegate.mm --- .../darwin/ios/framework/Source/FlutterAppDelegate.mm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index e0c4b572ec60d..5b4c773fc7295 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -115,10 +115,9 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center /** * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. */ -- (void)userNotificationCenter:(UNUserNotificationCenter *)center - didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void (^)(void))completionHandler - API_AVAILABLE(ios(10)) { +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + didReceiveNotificationResponse:(UNNotificationResponse*)response + withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10)) { if (@available(iOS 10.0, *)) { [_lifeCycleDelegate userNotificationCenter:center didReceiveNotificationResponse:response From e6f6b5707693376bb0a8f60a51e650734e4bc37e Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Jul 2019 18:08:38 -0700 Subject: [PATCH 06/23] format FlutterPluginAppLifeCycleDelegate.mm --- .../Source/FlutterPluginAppLifeCycleDelegate.mm | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm index 385a0739c0d90..52a520d364e6d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -261,10 +261,9 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center } } -- (void)userNotificationCenter:(UNUserNotificationCenter *)center - didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void (^)(void))completionHandler - API_AVAILABLE(ios(10)) { +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + didReceiveNotificationResponse:(UNNotificationResponse*)response + withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10)) { if (@available(iOS 10.0, *)) { for (id plugin in _pluginDelegates) { if (!plugin) { @@ -272,9 +271,8 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center } if ([plugin respondsToSelector:_cmd]) { [plugin userNotificationCenter:center - didReceiveNotificationResponse:response - withCompletionHandler:completionHandler]; - + didReceiveNotificationResponse:response + withCompletionHandler:completionHandler]; } } } From 6af5edd455cb17a4f2a456755b5da5ee1d3a8ab0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Fri, 19 Jul 2019 13:19:16 -0700 Subject: [PATCH 07/23] Formatting --- .../darwin/ios/framework/Headers/FlutterAppDelegate.h | 9 ++++----- .../Headers/FlutterPluginAppLifeCycleDelegate.h | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 170bf31b7419a..577b3fc41abe9 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -24,11 +24,10 @@ * code as necessary from FlutterAppDelegate.mm. */ FLUTTER_EXPORT -@interface FlutterAppDelegate - : UIResponder +@interface FlutterAppDelegate : UIResponder @property(strong, nonatomic) UIWindow* window; diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h index b21684440aff2..455d316b8e523 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h @@ -107,10 +107,9 @@ FLUTTER_EXPORT /** * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. */ -- (void)userNotificationCenter:(UNUserNotificationCenter *)center - didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void (^)(void))completionHandler - API_AVAILABLE(ios(10)); +- (void)userNotificationCenter:(UNUserNotificationCenter*)center + didReceiveNotificationResponse:(UNNotificationResponse*)response + withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10)); /** * Calls all plugins registered for `UIApplicationDelegate` callbacks in order of registration until From bd8ea0531713c9777c003b1dcdd08c47da4cf5b1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 12 Aug 2019 13:48:07 -0700 Subject: [PATCH 08/23] Ad if statement in FlutterAppDelegate --- .../darwin/ios/framework/Headers/FlutterAppDelegate.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 577b3fc41abe9..14cfa191a6951 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -24,13 +24,18 @@ * code as necessary from FlutterAppDelegate.mm. */ FLUTTER_EXPORT +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000 @interface FlutterAppDelegate : UIResponder - @property(strong, nonatomic) UIWindow* window; - @end +#else +@interface FlutterAppDelegate + : UIResponder +@property(strong, nonatomic) UIWindow* window; +@end +#endif #endif // FLUTTER_FLUTTERDARTPROJECT_H_ From e33de173f7fc5921e41cdffb4a88e679a89a9cef Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 12 Aug 2019 13:50:49 -0700 Subject: [PATCH 09/23] Use __IPHONE_OS_VERSION_MAX_ALLOWED instead --- .../platform/darwin/ios/framework/Headers/FlutterAppDelegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 14cfa191a6951..e4fc6eb6df107 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -24,7 +24,7 @@ * code as necessary from FlutterAppDelegate.mm. */ FLUTTER_EXPORT -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000 +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 @interface FlutterAppDelegate : UIResponder Date: Tue, 13 Aug 2019 11:12:59 -0700 Subject: [PATCH 10/23] Guard only a single line --- .../ios/framework/Headers/FlutterAppDelegate.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index e4fc6eb6df107..4ddf4d61f6769 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -24,18 +24,12 @@ * code as necessary from FlutterAppDelegate.mm. */ FLUTTER_EXPORT -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 @interface FlutterAppDelegate : UIResponder = __IPHONE_10_0 UNUserNotificationCenterDelegate> -@property(strong, nonatomic) UIWindow* window; -@end -#else -@interface FlutterAppDelegate - : UIResponder -@property(strong, nonatomic) UIWindow* window; -@end -#endif + #endif + > #endif // FLUTTER_FLUTTERDARTPROJECT_H_ From c6c2eea071511ea89b3f6dd8ef5b0dc7be1dfd8e Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 13 Aug 2019 11:32:33 -0700 Subject: [PATCH 11/23] Keep availability checks in headers --- .../ios/framework/Headers/FlutterPlugin.h | 2 +- .../framework/Source/FlutterAppDelegate.mm | 21 +++++------- .../FlutterPluginAppLifeCycleDelegate.mm | 32 +++++++------------ 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 8700c9488aa39..79e49f9c0933b 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -388,7 +388,7 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject* * calls as `UNUserNotificationCenterDelegate` when they are added to * `addApplicationLifeCycleDelegate`. */ -- (void)registerAsUserNotificationCenterDelegate; +- (void)registerAsUserNotificationCenterDelegate API_AVAILABLE(ios(10)); @end NS_ASSUME_NONNULL_END; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 8dc8f4d5eef3a..d97d9e01b91a0 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -83,13 +83,10 @@ - (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, *)) { - [_lifeCycleDelegate userNotificationCenter:center - willPresentNotification:notification - withCompletionHandler:completionHandler]; - } + (void (^)(UNNotificationPresentationOptions options))completionHandler { + [_lifeCycleDelegate userNotificationCenter:center + willPresentNotification:notification + withCompletionHandler:completionHandler]; } /** @@ -97,12 +94,10 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center */ - (void)userNotificationCenter:(UNUserNotificationCenter*)center didReceiveNotificationResponse:(UNNotificationResponse*)response - withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10)) { - if (@available(iOS 10.0, *)) { - [_lifeCycleDelegate userNotificationCenter:center - didReceiveNotificationResponse:response - withCompletionHandler:completionHandler]; - } + withCompletionHandler:(void (^)(void))completionHandler { + [_lifeCycleDelegate userNotificationCenter:center + didReceiveNotificationResponse:response + withCompletionHandler:completionHandler]; } - (BOOL)application:(UIApplication*)application diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm index df3d89ae217c5..677dac7bfc012 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -276,33 +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 - withCompletionHandler:completionHandler]; - } + 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 API_AVAILABLE(ios(10)) { - if (@available(iOS 10.0, *)) { - for (id plugin in _pluginDelegates) { - if (!plugin) { - continue; - } - if ([plugin respondsToSelector:_cmd]) { - [plugin userNotificationCenter:center - didReceiveNotificationResponse:response - withCompletionHandler:completionHandler]; - } + withCompletionHandler:(void (^)(void))completionHandler { + for (id delegate in _delegates) { + if ([delegate respondsToSelector:_cmd]) { + [delegate userNotificationCenter:center + didReceiveNotificationResponse:response + withCompletionHandler:completionHandler]; } } } From 5618d269a4985f6b61d23243fe6d5bbb47bb60b7 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 13 Aug 2019 12:28:40 -0700 Subject: [PATCH 12/23] Remove check of UNUserNotificationCenter --- .../darwin/ios/framework/Source/FlutterAppDelegate.mm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index d97d9e01b91a0..f2adbd35ba1ae 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -186,11 +186,7 @@ - (void)addApplicationLifeCycleDelegate:(NSObject*)delegate { } - (void)registerAsUserNotificationCenterDelegate { - if ([UNUserNotificationCenter class] != nil) { - // iOS 10 or later - // For iOS 10 display notification (sent via APNS) - [UNUserNotificationCenter currentNotificationCenter].delegate = self; - } + [UNUserNotificationCenter currentNotificationCenter].delegate = self; } #pragma mark - UIApplicationDelegate method dynamic implementation From 7d826378277bf649b66268e7fb544e7617fe7c28 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 13 Aug 2019 12:53:30 -0700 Subject: [PATCH 13/23] Move UNUserNotificationCenterDelegate to FlutterApplicationLifeCycleDelegate --- .../ios/framework/Headers/FlutterAppDelegate.h | 13 ++++++------- .../darwin/ios/framework/Headers/FlutterPlugin.h | 3 +++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 4ddf4d61f6769..8684a22ea7733 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -24,12 +24,11 @@ * code as necessary from FlutterAppDelegate.mm. */ FLUTTER_EXPORT -@interface FlutterAppDelegate : UIResponder = __IPHONE_10_0 - UNUserNotificationCenterDelegate> - #endif - > +@interface FlutterAppDelegate + : UIResponder + +@property(strong, nonatomic) UIWindow* window; + +@end #endif // FLUTTER_FLUTTERDARTPROJECT_H_ diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 79e49f9c0933b..c8233e2ca7007 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_4 + +#endif @optional /** * Called if this has been registered for `UIApplicationDelegate` callbacks. From 204d8b13759073c7bce34ee57f36039347211fbb Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 20 Aug 2019 14:40:15 -0700 Subject: [PATCH 14/23] Make FlutterAppLifeCycleProvider conform to UNUserNotificationCenterDelegate protocol --- .../darwin/ios/framework/Headers/FlutterPlugin.h | 16 ++++++---------- .../ios/framework/Source/FlutterAppDelegate.mm | 4 ---- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index c8233e2ca7007..227c63308d358 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -23,9 +23,6 @@ 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_4 - -#endif @optional /** * Called if this has been registered for `UIApplicationDelegate` callbacks. @@ -382,16 +379,15 @@ 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; - -/** - * Implement this in the `UIAppDelegate` of your app to enable Flutter plugins to receive - * calls as `UNUserNotificationCenterDelegate` when they are added to - * `addApplicationLifeCycleDelegate`. - */ -- (void)registerAsUserNotificationCenterDelegate API_AVAILABLE(ios(10)); @end NS_ASSUME_NONNULL_END; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index f2adbd35ba1ae..ba3743b0aada9 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -185,10 +185,6 @@ - (void)addApplicationLifeCycleDelegate:(NSObject*)delegate { [_lifeCycleDelegate addDelegate:delegate]; } -- (void)registerAsUserNotificationCenterDelegate { - [UNUserNotificationCenter currentNotificationCenter].delegate = self; -} - #pragma mark - UIApplicationDelegate method dynamic implementation - (BOOL)respondsToSelector:(SEL)selector { From 168c67446149fcdbfbafbc6f309ccbfd01421427 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 20 Aug 2019 14:47:29 -0700 Subject: [PATCH 15/23] Add single quotes --- shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 227c63308d358..53a1c5471dcaa 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -380,8 +380,8 @@ 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. + * For plugins to receive events from `UNUserNotificationCenter`, register this as the + * `UNUserNotificationCenterDelegate`. */ @protocol FlutterAppLifeCycleProvider #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 From 8e0def6352b96a0db68c78bb5572c19b69eae41d Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 20 Aug 2019 14:56:55 -0700 Subject: [PATCH 16/23] Formatting --- shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 53a1c5471dcaa..faf8b779f450f 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -385,7 +385,7 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject* */ @protocol FlutterAppLifeCycleProvider #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 - + #endif - (void)addApplicationLifeCycleDelegate:(NSObject*)delegate; @end From 25011589ef96d99bdfb4da9316de3a614e36967b Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 22 Aug 2019 13:30:59 -0700 Subject: [PATCH 17/23] Remove delegate methods and use protocol in FlutterPlugin.h --- .../ios/framework/Headers/FlutterPlugin.h | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index faf8b779f450f..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,22 +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)); - -/** - * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks. - */ -- (void)userNotificationCenter:(UNUserNotificationCenter*)center - didReceiveNotificationResponse:(UNNotificationResponse*)response - withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10)); - /** * Called if this has been registered for `UIApplicationDelegate` callbacks. * From 8875d3574190c11797c32209bef07622fed83672 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 22 Aug 2019 13:33:46 -0700 Subject: [PATCH 18/23] Update FlutterPluginAppLifeCycleDelegate.h --- .../FlutterPluginAppLifeCycleDelegate.h | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h index 7b2f4d04f15ba..9541925f3b1d6 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,22 +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 `UNUserNotificationCenterDelegate` callbacks. - */ -- (void)userNotificationCenter:(UNUserNotificationCenter*)center - didReceiveNotificationResponse:(UNNotificationResponse*)response - withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10)); - /** * Calls all plugins registered for `UIApplicationDelegate` callbacks in order of registration until * some plugin handles the request. From fb05b3a44925ec0f7e86e67b19efc013f840b221 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 22 Aug 2019 13:39:53 -0700 Subject: [PATCH 19/23] Formatting --- .../ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h index 9541925f3b1d6..95a4f233409d9 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN FLUTTER_EXPORT @interface FlutterPluginAppLifeCycleDelegate : NSObject #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 - + #endif /** From 4ab5307e19f1f13f94e1c34dc4989f69b60efe6f Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 22 Aug 2019 13:40:52 -0700 Subject: [PATCH 20/23] If Statement formatting --- .../ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h index 95a4f233409d9..a89d27c4e1b3a 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h @@ -14,9 +14,9 @@ NS_ASSUME_NONNULL_BEGIN */ FLUTTER_EXPORT @interface FlutterPluginAppLifeCycleDelegate : NSObject -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 + #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 -#endif + #endif /** * Registers `delegate` to receive life cycle callbacks via this FlutterPluginAppLifecycleDelegate From d4415f4f4066e5f6c77d193336e66daf6e9c514f Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 29 Aug 2019 12:04:34 -0700 Subject: [PATCH 21/23] Formatting --- .../ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h index a89d27c4e1b3a..95a4f233409d9 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h @@ -14,9 +14,9 @@ NS_ASSUME_NONNULL_BEGIN */ FLUTTER_EXPORT @interface FlutterPluginAppLifeCycleDelegate : NSObject - #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 - #endif +#endif /** * Registers `delegate` to receive life cycle callbacks via this FlutterPluginAppLifecycleDelegate From 1002702beb0b3f3cc9a7a401ff988495feca5d10 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 5 Sep 2019 16:12:32 -0700 Subject: [PATCH 22/23] Add respondsToSelector to optional methods --- .../ios/framework/Source/FlutterAppDelegate.mm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index ba3743b0aada9..f3a01066137f1 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -84,9 +84,11 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler: (void (^)(UNNotificationPresentationOptions options))completionHandler { - [_lifeCycleDelegate userNotificationCenter:center - willPresentNotification:notification - withCompletionHandler:completionHandler]; + if (_lifeCycleDelegate respondsToSelector:_cmd)) { + [_lifeCycleDelegate userNotificationCenter:center + willPresentNotification:notification + withCompletionHandler:completionHandler]; + } } /** @@ -95,9 +97,11 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center - (void)userNotificationCenter:(UNUserNotificationCenter*)center didReceiveNotificationResponse:(UNNotificationResponse*)response withCompletionHandler:(void (^)(void))completionHandler { - [_lifeCycleDelegate userNotificationCenter:center - didReceiveNotificationResponse:response - withCompletionHandler:completionHandler]; + if (_lifeCycleDelegate respondsToSelector:_cmd)) { + [_lifeCycleDelegate userNotificationCenter:center + didReceiveNotificationResponse:response + withCompletionHandler:completionHandler]; + } } - (BOOL)application:(UIApplication*)application From 3e299e47912a0ee0e570b393d92d2640bd375e84 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 5 Sep 2019 16:15:21 -0700 Subject: [PATCH 23/23] Square brackets --- .../darwin/ios/framework/Source/FlutterAppDelegate.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index f3a01066137f1..28a4a153e2cc1 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -84,7 +84,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler: (void (^)(UNNotificationPresentationOptions options))completionHandler { - if (_lifeCycleDelegate respondsToSelector:_cmd)) { + if ([_lifeCycleDelegate respondsToSelector:_cmd]) { [_lifeCycleDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; @@ -97,7 +97,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center - (void)userNotificationCenter:(UNUserNotificationCenter*)center didReceiveNotificationResponse:(UNNotificationResponse*)response withCompletionHandler:(void (^)(void))completionHandler { - if (_lifeCycleDelegate respondsToSelector:_cmd)) { + if ([_lifeCycleDelegate respondsToSelector:_cmd]) { [_lifeCycleDelegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];