-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ios][docs] Add support for options which allows displaying notifications in foreground #4802
Conversation
…message to allow displaying push notification in foreground
…ion in `app.json`
It will only be actually displayed after #4802 is merged so that the notification will be displayed in foreground
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, thanks! I just have one question, which is: what is the behavior with local notifications? Do we also need to add a displayInForeground
option to those, or do they already display in the foreground? I don't think that needs to block this PR from landing -- fine to just worry about pushes -- but let's at least create an issue to track it if we need to.
@esamelson Thanks for pointing that out! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome 👍 🙏 🎉
…in push notifications (#4787) * [android] Add basic support for displaying an image in push notification * [ios] Add support for displaying rich content This is done by creating a `UNNotificationServiceExtension`. Ref: - https://docs.leanplum.com/docs/adding-images-to-push-notifications - https://developer.apple.com/documentation/usernotifications/unnotificationattachment - https://stackoverflow.com/a/40734571/2603230 * [ios] Change variable names * [ios] Use escaping for callback * [ios] Minor change * [ios] Add support for displaying rich content without extension * [ios] Use `response.suggestedFilename` instead of manually finding the extension * [ios] Use Objective-C instead of Swift for UNNotificationServiceExtension * [ios] Add support for receiving and using user options for rich content * [android] Fix crash due to IllegalStateException when handling invalid rich content (image) URL * [android] Add support for using a custom icon for push notification * [android] Add support for push notification body with rich content options though none of those options are supported on Android and are ignored * [android] Do not display any rich content if `isMultiple` * [android] Add support for `thumbnailHidden` option * [docs] Add documentation for rich content in push notification * [docs] Add note for rich content displaying priority on iOS * Update CHANGELOG.md * [ios] Add support for an option `_displayInForeground` to allow displaying push notification in foreground * Update push-notifications.md * [ios] Fix formatting * Update push-notifications.md * Revert changes related to `_displayInForeground` (doing it in a new branch) * [ios] Use spaces instead of tabs to be consistent * [ncl] Add rich content push notification demo It will only be actually displayed after #4802 is merged so that the notification will be displayed in foreground * [ncl] Add alert for Android to notify that rich content other than images are only supported on iOS * [ncl] Minor change to rich content video source * [test-suite] Add tests for push notifications * [test-suite] Minor change to push notifications test * Update docs/pages/versions/unversioned/guides/push-notifications.md Co-Authored-By: Eric Samelson <esamelson@users.noreply.github.com> * Update NotificationService.m * Update NotificationService.h * [test-suite] Restrict the test to the receipt of the notification #4787 (comment) * [android] Log exceptions * Update PushNotificationHelper.java * [docs] Add notes about GIFs on Android #4787 (comment) * [ios] Rename `NotificationService` to `ExNotificationService` https://github.com/expo/expo/pull/4787/files#discussion_r305483876 * [ios] Rename `NotificationService` file to `EXNotificationService` file * [ios] Minor change * [ncl] Add "image with a custom icon" for NotificationScreen
Why
https://expo.canny.io/feature-requests/p/implement-foreground-notifications-on-ios-using-new-native-willpresentnotificati
Currently, on iOS, all notifications received when the app is in foreground have to be handled by the developer separately. Since iOS 10, iOS supports also displaying the notification banner when the app is in foreground. This PR gives the developer an option to choose to let the system handles and displays the notification when the app is in foreground. (Ref: https://stackoverflow.com/a/40756206/2603230)
How
In
userNotificationCenter
willPresentNotification
, we first check ifnotification.iosDisplayInForeground
inapp.json
is set to true. We also check if_displayInForeground
is set for the individual message (which always override the prior option).By defaults,
notification.iosDisplayInForeground
will befalse
(the same as before), so there will not be any breaking changes to the app's behavior.In other words, the notification will be shown in foreground if:
notification.iosDisplayInForeground
istrue
and_displayInForeground
is notfalse
, or_displayInForeground
istrue
Test Plan
Different cases:
Each column is a value for
notification.iosDisplayInForeground
and each row is a value for_displayInForeground
. A "✓" means the notification will be displayed in foreground.