Skip to content

notif ios: Buffer notification tap events; same as on Android#2229

Open
rajveermalviya wants to merge 2 commits into
zulip:mainfrom
rajveermalviya:pr-ios-notif-fix
Open

notif ios: Buffer notification tap events; same as on Android#2229
rajveermalviya wants to merge 2 commits into
zulip:mainfrom
rajveermalviya:pr-ios-notif-fix

Conversation

@rajveermalviya
Copy link
Copy Markdown
Member

@rajveermalviya rajveermalviya commented Mar 17, 2026

It turns out that userNotificationCenter(_:didReceive:withCompletionHandler:) does execute when app is terminated and later opened by tapping on a notification, so there is no need to check launchOptions in application(_:didFinishLaunchingWithOptions:) to handle this case.

But because we currently handle both cases, there is a potential bug where if both are handled, it could cause double navigations for the same notification. This is not observed in practice, probably because we do not buffer events from userNotificationCenter(_:didReceive:withCompletionHandler:) currently and those events may be missed until Flutter init is complete and the handler (in NotificationOpenService.init) is setup.

So, remove the unnecessary handlers for launchOptions. This also unifies our notification opening implementation between Android and iOS, where we handle all types of notification tap events via the same Pigeon EventChannel API.

@rajveermalviya rajveermalviya added the maintainer review PR ready for review by Zulip maintainers label Mar 19, 2026
@rajveermalviya rajveermalviya marked this pull request as ready for review March 19, 2026 14:25
@rajveermalviya rajveermalviya marked this pull request as draft March 20, 2026 20:38
Copy link
Copy Markdown
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a helpful simplification! I haven't tested manually yet, and see one comment below. I'll take another look (and do that manual testing) when this is un-marked as a draft.

Comment thread lib/widgets/app.dart Outdated
// https://github.com/zulip/zulip-flutter/pull/2043#discussion_r2794138972
// TODO it'd be nice to avoid that glitch by controlling the initial route.
// We accept this glitch as a workaround for an upstream issue:
// https://github.com/flutter/flutter/issues/178305
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linked Flutter issue appears to be Android-specific, so this reasoning doesn't hold in the iOS case.

Comment thread pigeon/notifications.dart
}

@HostApi()
abstract class NotificationHostApi {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep NotificationHostApi (without any methods), as a home for future functionality e.g. two methods I propose in #2257?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this, but when we have an empty NotificationHostApi then Pigeon generates a _extractReplyValueOrThrow which ends up being unused. And because of that analyzer ends up complaining about it.

@rajveermalviya rajveermalviya force-pushed the pr-ios-notif-fix branch 2 times, most recently from 32008cd to 43cc2ad Compare April 29, 2026 18:41
@rajveermalviya rajveermalviya marked this pull request as ready for review April 29, 2026 18:42
@rajveermalviya
Copy link
Copy Markdown
Member Author

This is ready for review now.

It turns out that
`userNotificationCenter(_:didReceive:withCompletionHandler:)`
does execute when app is terminated and later opened by
tapping on a notification, so there is no need to check
`launchOptions` in `application(_:didFinishLaunchingWithOptions:)`
to handle this case.

But because we currently handle both cases, there is a potential
bug where if both are handled, it could cause double navigations
for the same notification. This is not observed in practice,
probably because we do not buffer events from
`userNotificationCenter(_:didReceive:withCompletionHandler:)`
currently and those events may be missed until Flutter init is
complete and the handler (in NotificationOpenService.init) is
setup.

So, remove the unnecessary handlers for `launchOptions`. This also
unifies our notification opening implementation between Android and
iOS, where we handle all types of notification tap events via the
same Pigeon EventChannel API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer review PR ready for review by Zulip maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants