Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

feature(ios): Add support for subtitle notification property #2063

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ PushNotification.localNotification({

/* iOS only properties */
category: "", // (optional) default: empty string
subtitle: "My Notification Subtitle", // (optional) smaller title below notification title

/* iOS and Android properties */
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
Expand Down
5 changes: 3 additions & 2 deletions example/NotifService.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ export default class NotifService {
ongoing: false, // (optional) set whether this is an "ongoing" notification
actions: ['Yes', 'No'], // (Android only) See the doc for notification actions to know more
invokeApp: true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true

when: null, // (optionnal) Add a timestamp pertaining to the notification (usually the time the event occurred). For apps targeting Build.VERSION_CODES.N and above, this time is not shown anymore by default and must be opted into by using `showWhen`, default: null.
usesChronometer: false, // (optional) Show the `when` field as a stopwatch. Instead of presenting `when` as a timestamp, the notification will show an automatically updating display of the minutes and seconds since when. Useful when showing an elapsed time (like an ongoing phone call), default: false.
timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null

/* iOS only properties */
category: '', // (optional) default: empty string

subtitle: "My Notification Subtitle", // (optional) smaller title below notification title

/* iOS and Android properties */
id: this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
title: 'Local Notification', // (optional)
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ Notifications.localNotification = function({...details}) {
soundName = ''; // empty string results in no sound (and no vibration)
}

// for valid fields see: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html
// for valid fields see: https://github.com/react-native-push-notification-ios/push-notification-ios#addnotificationrequest

this.handler.addNotificationRequest({
id: (!details.id ? Math.floor(Math.random() * Math.pow(2, 32)).toString() : details.id),
title: details.title,
subtitle: details.subtitle,
body: details.message,
badge: details.number,
sound: soundName,
Expand Down Expand Up @@ -252,6 +253,7 @@ Notifications.localNotificationSchedule = function({...details}) {
id: (!details.id ? Math.floor(Math.random() * Math.pow(2, 32)).toString() : details.id),
fireDate: details.date.toISOString(),
title: details.title,
subtitle: details.subtitle,
body: details.message,
sound: soundName,
isSilent: details.playSound === false,
Expand Down Expand Up @@ -364,6 +366,7 @@ Notifications._transformNotificationObject = function(data, isFromBackground = n
data: notifData,
badge: data.getBadgeCount(),
title: data.getTitle(),
subtitle: data.getSubtitle(),
soundName: data.getSound(),
fireDate: Date.parse(data._fireDate),
action: data.getActionIdentifier(),
Expand Down