Skip to content

Commit

Permalink
[flutter_local_notifications] fix crash occurring for notification ac…
Browse files Browse the repository at this point in the history
…tions that don't have a callback to handle them (#1739)

* fix crash occurring for notification actions that don't have a callback to handle them

* Clang Format

Co-authored-by: runner <[email protected]>
  • Loading branch information
MaikuB and runner authored Oct 8, 2022
1 parent b4ec7d7 commit 6d3e1ab
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 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 @@
# [12.0.1]

* [Android][iOS] fixed issue [1721](https://github.com/MaikuB/flutter_local_notifications/issues/1721) where a crash occurs upon tapping on a notification action fbut the `onDidReceiveBackgroundNotificationResponse` optional callback hasn't been specified.

# [12.0.0]

* Bumped `dbus` dependency via `flutter_local_notifications_linux`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ private void startEngine(Context context) {
return;
}

FlutterCallbackInformation dispatcherHandle = preferences.lookupDispatcherHandle();
if (dispatcherHandle == null) {
Log.w(TAG, "Callback information could not be retrieved");
return;
}

FlutterInjector injector = FlutterInjector.instance();
FlutterLoader loader = injector.flutterLoader();

Expand All @@ -80,7 +86,6 @@ private void startEngine(Context context) {
engine = new FlutterEngine(context);
DartExecutor dartExecutor = engine.getDartExecutor();

FlutterCallbackInformation dispatcherHandle = preferences.lookupDispatcherHandle();
initializeEventChannel(dartExecutor);

String dartBundlePath = loader.findAppBundlePath();
Expand Down
14 changes: 7 additions & 7 deletions flutter_local_notifications/ios/Classes/FlutterEngineManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ - (void)startEngineIfNeeded:(ActionEventSink *)actionEventSink
NSNumber *dispatcherHandle =
[_persistentState objectForKey:@"dispatcher_handle"];

backgroundEngine =
[[FlutterEngine alloc] initWithName:@"FlutterLocalNotificationsIsolate"
project:nil
allowHeadlessExecution:true];

FlutterCallbackInformation *info = [FlutterCallbackCache
lookupCallbackInformation:[dispatcherHandle longValue]];

if (!info) {
NSLog(@"callback information could not be retrieved");
abort();
NSLog(@"Callback information could not be retrieved");
return;
}

NSString *entryPoint = info.callbackName;
NSString *uri = info.callbackLibraryPath;

backgroundEngine =
[[FlutterEngine alloc] initWithName:@"FlutterLocalNotificationsIsolate"
project:nil
allowHeadlessExecution:true];

dispatch_async(dispatch_get_main_queue(), ^{
FlutterEventChannel *channel = [FlutterEventChannel
eventChannelWithName:
Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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: 12.0.0
version: 12.0.1
homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications
issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues

Expand Down

0 comments on commit 6d3e1ab

Please sign in to comment.