ben-xD / push

Push notifications in Flutter without firebase_messaging.
https://pub.dev/packages/push
36 stars 22 forks source link

iOS: Local Notifications do not show up in notification center when using `push` #29

Closed Bungeefan closed 10 months ago

Bungeefan commented 11 months ago

I am experiencing a weird bug, I implemented push to receive remote notifications, but as these are not showing while the app is in the foreground, I also had to add flutter_local_notifications to show them in the onMessage call from this package. This works on both of our supported platforms, Android and iOS, quite fine.

Problem

However, on iOS these local notifications are only shown as banner and do not persist in the notification center, first I thought that this could be some bug/limitation in the flutter_local_notifications library or from iOS itself, but using their example it works flawlessly. So back to push, I tried the example from this repo and experienced the same behavior as in our app. Weird, as push AFAIK doesn't manage local notifications in any way.

As a final test, I only removed the push dependency from our app and tried again sending a local notification (with the same code as before), and lo and behold it worked just fine and even showed up in the center afterward. I even completely reinstalled our app to avoid any user setting from our side affecting it. No luck.

Now what?

I have honestly no clue why this behavior happens, however, I am now quite sure that the culprit lies, at least partly, in this package. Furthermore, I couldn't find any cancel calls to the notification center in push_ios (why should there even be any) and I couldn't yet identify any other possible reason why this could be happening.

I will try to continue investigating to hopefully find a solution/reason, but my iOS developing experience is very limited, therefore, I would be quite happy if anybody with more knowledge could assist me in this weird case. I am ready to test/record everything needed!

Bungeefan commented 11 months ago

One possible reason could be the hard-coded UNNotificationPresentationOptions in the following code that handles local notifications:

https://github.com/ben-xD/push/blob/0b0ce07c268a5b487a4cd784443abd86eb834e92/push_ios/ios/Classes/UserNotificationCenterDelegateHandlers.swift#L23-L30

Which would explain why, even though the list option was specified when sending the local notification, the notification still vanished.

A better "equivalent" to the deprecated alert option (if that was the desired target for this code) would be banner and list according to the Apple Docs. So even though, this would still override/replace the options specified in flutter_local_notifications, it would achieve feature parity with the APNS notifications which is probably the most desired case when using this package combination.

Unfortunately, I am currently unable to continue code research for this issue from my side.

Arley011 commented 10 months ago

@Bungeefan, I created a PR that should resolve your issue in case your local notification includes appropriate parameters - https://github.com/ben-xD/push/pull/33

Bungeefan commented 10 months ago

Thanks to @Arley011, this has been resolved with push 1.0.5