Skip to content

Commit

Permalink
Prevent iOS notifications created outside of the plugin from trigger …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
MaikuB authored Jan 18, 2020
1 parent 9e2b539 commit 09a9063
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions flutter_local_notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications/example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 09a9063

Please sign in to comment.