Description:
Using flutter_local_notifications https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications and onesginal_flutter plugins together leads to an issue with scheduled local notifications.
Local Notification will not be shown when the app is on the foreground, moreover, after clicking on it, the onSelectNotification is not called.
Everything works fine without OneSignal plugin.
Environment
flutter_local_notifications: ^0.9.1+2
onesignal_flutter: ^2.3.1
Flutter 1.12.13+hotfix.5 • channel stable
Steps to Reproduce Issue:
Create a new Flutter project
Anything else:
Any help would be appreciated.
Thanks!
@Mapk26 It looks like [email protected] made a breaking change that requires some extra iOS setups now.
https://github.com/MaikuB/flutter_local_notifications/blob/97966616ae6b72d1e3b34bae36434a7b0b742401/flutter_local_notifications/CHANGELOG.md#090
From a quick look it seems to be referring to the following section:
https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications#ios-integration
Never used OneSignal with or without the flutter_local_notifications plugin but for context that change was made because the Flutter team had made changes within the engine to allow for multiple plugins to handle the methods that belong to the UNUserNotificationCenterDelegate protocol. Registering the UNUserNotificationCenterDelegate as part of the AppDelegate is part of the changes required for this mechanism within Flutter to work. In my experience with firebase_messaging, this also required disabling method swizzling (note I'm not an expert with regards to swizzling). I mention these details in case there are changes required by OneSignal. As far as I see, none are needed by flutter_local_notifications as it has changed to match the approach required by Flutter.
Did you fixed this?
We're running into this same issue. Is there a fix or a solution to this?
It looks like this issue was discussed here: https://github.com/MaikuB/flutter_local_notifications/issues/440
If OneSignal does not attempt to resolve this issue, we'll have to switch to Firebase instead. Not being able to do both local and remote push notification is a huge issue.
I'm running into the same issue. @kbokarius did you find a fix or a workaround?
@AlessioValentiniAesys unfortunately not. We're not yet focused on remote push notifications and only need local notifications, so we simply ended up removing the OneSignal pod from the project. We'll end up switching to Firebase if OneSignal doesn't get this resolved by the time we need remote push.
Why again is this and any other issue regarding this topic closed even though it is not resolved?
The change mentioned on the flutter_local_notifications plugin README obviously does not solve this problem which still occurs.
@AlessioValentiniAesys have you had any luck with this topic so far or did you also switch to another remote push provider?
@jkasten2 also pinging you as well, is this on the radar?
We're going to switch to Firebase because we will soon need both remote and local notification functionality. No reason to get stuck on this and go down a rabbit hole with OneSignal.
@reesz I can't help you because we switched to Firebase.
Damn that sucks, since we're already using OneSignal from a previous version of the app with a huge subscriber base.
@AlessioValentiniAesys because you're saying you "switched" does this mean you also were using OneSignal before and somehow migrated? Did you manage to keep the existing subscribers in any way?
Just in case anyone else comes across this thread in the future:
One thing I found was, that if you place this inside your AppDelegate.swift
override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("===========")
print("** didReceive")
print(response.notification.request.content.userInfo); // <- Here you can extract the LocalNotification as well as the OneSignal payload.
print("===========")
completionHandler()
}
you can intercept the Notification/Push interaction handler for both plugins, extract & pass the extracted payload to flutter through an own MethodChannel.
Warning: This breaks the regular OneSignal callback as well, so probably also a lot of the SDK features regarding analytics. And haven't looked into the Android side of things so far.
We were using OneSignal in test so we had no problem to switch to Firebase.
We will be revisiting this shortly.
➤ Jon Fishman commented:
Sorry I created another ticket for this: Flutter Local Notification Issue ( https://app.asana.com/0/search/1199669044574148/1199619162289904 )
This is nice we sync data from Github
Hi, any news about this issue? I prefer not to switch to Firebase. Thank you.
To reiterate @xjerryg comment, was wondering if there is a status update regarding this issue. Thanks!
Hello I believe this just requires a fairly simple setup change. Please let me know if you are still having issues after trying these steps
If the application is subclassing FlutterAppDelegate (probably most common) the apps simply need to implement the UNUserNotificationCenter protocol in the AppDelegate.h file.
@interface AppDelegate : FlutterAppDelegate <UNUserNotificationCenterDelegate>
set itself as the UNUserNotificationCenterDelegate in application:didFinishLaunchingWithOptions:
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
}
Finally in the protocol method implementations call Super. This calls the FlutterAppDelegate version of these methods.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
[super userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
[super userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
If your Application is not subclassing FlutterAppDelegate as described in the Flutter doc here the app will do something similar but will call the method directly on the _lifeCycleDelegate instead of Super.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
[_lifeCycleDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
[_lifeCycleDelegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
Most helpful comment
We will be revisiting this shortly.