From 90bf9e04fb1910e70c80ed2b61506b7c3108cb9a Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Mon, 9 Sep 2019 16:10:42 -0700 Subject: [PATCH] Guard availability of user notification related methods to iOS 10.0 * `NS_AVAILABLE_IOS(10_0)` makes us tell our compiler that the method needs to be stamped into the TU but we promise to do stuff in it only on iOS 10.0 and above. * `@availability` ensures that if those methods are called on iOS versions less than 10.0, we will do nothing with it. This guards us against the case where iOS introduced the functionality privately in older versions of iOS. --- .../framework/Source/FlutterAppDelegate.mm | 25 +++++++++------- .../FlutterPluginAppLifeCycleDelegate.mm | 29 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 28a4a153e2cc1..998211ed779a0 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -83,11 +83,14 @@ - (void)application:(UIApplication*)application - (void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler: - (void (^)(UNNotificationPresentationOptions options))completionHandler { - if ([_lifeCycleDelegate respondsToSelector:_cmd]) { - [_lifeCycleDelegate userNotificationCenter:center - willPresentNotification:notification - withCompletionHandler:completionHandler]; + (void (^)(UNNotificationPresentationOptions options))completionHandler + NS_AVAILABLE_IOS(10_0) { + if (@available(iOS 10.0, *)) { + if ([_lifeCycleDelegate respondsToSelector:_cmd]) { + [_lifeCycleDelegate userNotificationCenter:center + willPresentNotification:notification + withCompletionHandler:completionHandler]; + } } } @@ -96,11 +99,13 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center */ - (void)userNotificationCenter:(UNUserNotificationCenter*)center didReceiveNotificationResponse:(UNNotificationResponse*)response - withCompletionHandler:(void (^)(void))completionHandler { - if ([_lifeCycleDelegate respondsToSelector:_cmd]) { - [_lifeCycleDelegate userNotificationCenter:center - didReceiveNotificationResponse:response - withCompletionHandler:completionHandler]; + withCompletionHandler:(void (^)(void))completionHandler NS_AVAILABLE_IOS(10_0) { + if (@available(iOS 10.0, *)) { + if ([_lifeCycleDelegate respondsToSelector:_cmd]) { + [_lifeCycleDelegate userNotificationCenter:center + didReceiveNotificationResponse:response + withCompletionHandler:completionHandler]; + } } } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm index 677dac7bfc012..8c7877b44d50b 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -275,24 +275,29 @@ - (void)application:(UIApplication*)application - (void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler: - (void (^)(UNNotificationPresentationOptions options))completionHandler { - for (NSObject* delegate in _delegates) { - if ([delegate respondsToSelector:_cmd]) { - [delegate userNotificationCenter:center - willPresentNotification:notification - withCompletionHandler:completionHandler]; + (void (^)(UNNotificationPresentationOptions options))completionHandler + NS_AVAILABLE_IOS(10_0) { + if (@available(iOS 10.0, *)) { + 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]; + withCompletionHandler:(void (^)(void))completionHandler NS_AVAILABLE_IOS(10_0) { + if (@available(iOS 10.0, *)) { + for (id delegate in _delegates) { + if ([delegate respondsToSelector:_cmd]) { + [delegate userNotificationCenter:center + didReceiveNotificationResponse:response + withCompletionHandler:completionHandler]; + } } } }