Skip to content
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

Merged
merged 9 commits into from
Jul 19, 2019

Conversation

hesyifei
Copy link
Contributor

@hesyifei hesyifei commented Jul 2, 2019

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 if notification.iosDisplayInForeground in app.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 be false (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 is true and _displayInForeground is not false, or
  • _displayInForeground is true

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.

true false not set
true
false
not set ✗ (default)

hesyifei added a commit that referenced this pull request Jul 2, 2019
It will only be actually displayed after #4802 is merged so that the notification will be displayed in foreground
Copy link
Contributor

@esamelson esamelson left a 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.

@hesyifei
Copy link
Contributor Author

@esamelson Thanks for pointing that out! willPresentNotification is called for both local and push notifications. So the notification.iosDisplayInForeground property in app.json will be applied to both local and push notifications. I have also added ios._displayInForeground option to LocalNotification. (8a5d402)

@hesyifei hesyifei requested a review from esamelson July 19, 2019 23:04
Copy link
Contributor

@esamelson esamelson left a comment

Choose a reason for hiding this comment

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

awesome 👍 🙏 🎉

@hesyifei hesyifei merged commit 19411e2 into master Jul 19, 2019
@hesyifei hesyifei deleted the @hesyifei/ios-display-in-foreground branch July 19, 2019 23:22
hesyifei added a commit that referenced this pull request Jul 25, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants