Closed orevial closed 6 months ago
Notification center does not work properly on a simulator. Apparently a known issue. I spent hours looking into this too - please test that specific feature on a real device.
I have the exact same problem on a real device (iPhone X with iOS 16.3.1). It really seem to be specific to my app because when I test on a newly created app I have no problem having the notifications in notification center.
Are you maybe aware of some conflict with other plugins (e.g. Firebase ?) or some config that might mess with your plugin ?
Hi, I'm sorry this is not working for you. It is definitely possible that another plugin interferes with the notification functionality, as some degree of cooperation is required. The AppDelegate
code you included adds the flutter app as a delegate for notifications, and the flutter framework then calls each FlutterPlugin
that implements UNUserNotificationCenterDelegate
when delegate action is required. Here is that code for the background_downloader:
@MainActor
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions
{
if ourCategories.contains(notification.request.content.categoryIdentifier) {
if #available(iOS 14.0, *) {
return UNNotificationPresentationOptions.list
} else {
return UNNotificationPresentationOptions.alert
}
}
return []
}
As you can see, it checks if the notification.request.content.categoryIdentifier
is "one of ours" and if not, returns []
. If another plugin that implements UNUserNotificationCenterDelegate
does not check and does not return []
when the notification category is not "theirs" then they effectively block notifications for other plugins that have been registered after that plugin.
There have been issues with this (e.g. see here for Firebase messaging, but I believe most have been resolved. Are you using other plugins that may do something with notifications and implement UNUserNotificationCenterDelegate
?
Oh wow, that could explain a lot, I didn't know there was some cooperation between plugins involved in the process. I'm using Firebase messaging for push notifs so that could potentially be it but from what I understand it should not conflict with your plugin now, right ?
Is there a way to maybe change the order in which the different plugins and their respective AppDelegate
are loaded, at least to confirm/infirm that there is a conflict with another plugin ?
Just disabled firebase_messaging
entirely in my app for the sake of the test, and it indeed fixes my issue, I can now see background_downloader
notifications in iOS notif center (even on simulator).
I will probably try and check what in Firebase messaging plugin is causing the issue and will probably a ticket there, do you know any workaround in the meantime ?
The order of plugin registration in this file is usually determined by the order in which the plugins are listed in the pubspec.yaml file. When you add a plugin to pubspec.yaml and run flutter pub get, the build system generates the GeneratedPluginRegistrant.java file and lists the plugins in the order they appear in pubspec.yaml.
You could try to put he Firebase entry after the background downloader entry. Let me know if that works or not.
You could try to put he Firebase entry after the background downloader entry. Let me know if that works or not.
I tried it but the problems remains
@orevial did you manage to solve the problem?
iOS notifications are not visible in the notification center.
When I run my app on an iPhone 15 simulator (with iOS 17.4) I can't get to make the notifications visible in the notification center.
I've tried by copying all
background_downloader
example widgets in my app and all my permissions seem to be correct, yet I don't have the notifications. I do have correct notifications when I runbackground_downloader
example app directly on the same simulator.Context:
as well as the background mode for fetching:
AppDelegate.swift
contain the appropriate piece of code:When the download is over, I can verify that the permission for notifications is granted, e.g.:
Permission for PermissionType.notifications was PermissionStatus.granted
I can also verify that in simulator notification settings:
post_install
steps into my Podfile, with no success.Am I missing something here for notifications to work on iOS ?
Env
I'm using
background_downloader: ^8.4.3
and Flutter 3.19.5