From 09a9063ed672e0fa4b290bb02e0f503d904fd17b Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sat, 18 Jan 2020 12:54:12 +1100 Subject: [PATCH] Prevent iOS notifications created outside of the plugin from trigger callbacks (#441) * Add checks on iOS side to determine if callbacks should be invoked to avoid issues with other notification plugins * rename method for checking if notification came from plugin * Bump Gradle plugin to 3.5.3 --- flutter_local_notifications/CHANGELOG.md | 4 ++++ flutter_local_notifications/android/build.gradle | 2 +- .../example/android/build.gradle | 2 +- .../ios/Classes/FlutterLocalNotificationsPlugin.m | 11 +++++++++-- flutter_local_notifications/pubspec.yaml | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/flutter_local_notifications/CHANGELOG.md b/flutter_local_notifications/CHANGELOG.md index 1b9688763..d41dab832 100644 --- a/flutter_local_notifications/CHANGELOG.md +++ b/flutter_local_notifications/CHANGELOG.md @@ -1,3 +1,7 @@ +# [1.0.0] +* **BREAKING CHANGE** [iOS] Added checks to ensure callbacks are only invoked for notifications originating from the plugin to improve compatibility with other notification plugins. +* [Android] Bump Gradle plugin to 3.5.3 + # [0.9.1+3] * Include notes in getting started section to emphasise that the steps in the integration guide for each platform needs to be done. * Move information in the readme on configuring resources to keep on Android. diff --git a/flutter_local_notifications/android/build.gradle b/flutter_local_notifications/android/build.gradle index c23d01f3f..9a2704bcc 100644 --- a/flutter_local_notifications/android/build.gradle +++ b/flutter_local_notifications/android/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:3.5.3' } } diff --git a/flutter_local_notifications/example/android/build.gradle b/flutter_local_notifications/example/android/build.gradle index f6838e08f..4e7ce9c95 100644 --- a/flutter_local_notifications/example/android/build.gradle +++ b/flutter_local_notifications/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:3.5.3' } } diff --git a/flutter_local_notifications/ios/Classes/FlutterLocalNotificationsPlugin.m b/flutter_local_notifications/ios/Classes/FlutterLocalNotificationsPlugin.m index 0e358fa7e..56355a1b5 100644 --- a/flutter_local_notifications/ios/Classes/FlutterLocalNotificationsPlugin.m +++ b/flutter_local_notifications/ios/Classes/FlutterLocalNotificationsPlugin.m @@ -190,7 +190,7 @@ - (void)initialize:(FlutterMethodCall * _Nonnull)call result:(FlutterResult _Non } UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; - if(launchNotification != nil) { + if(launchNotification != nil && [self isAFlutterLocalNotification:launchNotification.userInfo]) { NSString *payload = launchNotification.userInfo[PAYLOAD]; [self handleSelectNotification:payload]; } @@ -319,6 +319,10 @@ - (NSDictionary*)buildUserDict:(NSNumber *)id title:(NSString *)title presentAle return userDict; } +- (BOOL)isAFlutterLocalNotification:(NSDictionary *)userInfo { + return userInfo != nil && userInfo[NOTIFICATION_ID] && userInfo[TITLE] && userInfo[PRESENT_ALERT] && userInfo[PRESENT_SOUND] && userInfo[PRESENT_BADGE] && userInfo[PAYLOAD]; +} + - (void) showUserNotification:(NotificationDetails *) notificationDetails NS_AVAILABLE_IOS(10.0) { UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; UNNotificationTrigger *trigger; @@ -483,7 +487,7 @@ - (void)handleSelectNotification:(NSString *)payload { - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler NS_AVAILABLE_IOS(10.0) { - if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) { + if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier] && [self isAFlutterLocalNotification:response.notification.request.content.userInfo]) { NSString *payload = (NSString *) response.notification.request.content.userInfo[PAYLOAD]; if(initialized) { [self handleSelectNotification:payload]; @@ -508,6 +512,9 @@ - (void)application:(UIApplication*)application if(@available(iOS 10.0, *)) { return; } + if(![self isAFlutterLocalNotification:notification.userInfo]) { + return; + } NSMutableDictionary *arguments = [[NSMutableDictionary alloc] init]; arguments[ID]= notification.userInfo[NOTIFICATION_ID]; diff --git a/flutter_local_notifications/pubspec.yaml b/flutter_local_notifications/pubspec.yaml index e882c7801..cf799df6b 100644 --- a/flutter_local_notifications/pubspec.yaml +++ b/flutter_local_notifications/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_local_notifications description: A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform. -version: 0.9.1+3 +version: 1.0.0 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications dependencies: