Skip to content

Commit

Permalink
Adds category and alertAction properties to local notification detail…
Browse files Browse the repository at this point in the history
…s object

Summary:In order to use iOS notification actions with local notifications, we need to be able to specify a category string. This PR adds a category property to the `details` object used to create a local notification.

I also added support for the `alertAction` property, which is used to control the "slide to {alertAction}" text beneath the notification.

Finally, I added the doc for `userInfo` to `presentLocalNotification` (previously was only documented for `scheduleLocalNotification`.

**Test plan (required)**

I implemented the example from the [react-native-ios-notification-actions README](https://github.com/holmesal/react-native-ios-notification-actions), and created a couple of actions and grouped them under a category with identifier `something_happened`.

Prior to the changes in this PR, the shown local notification would not contain any actions.

With the changes in this PR, the shown local notification contains the specified actions.

Like so:
![demo](https://camo.githubusercontent.com/c4a86
Closes #5994

Differential Revision: D2953919

Pulled By: nicklockwood

fb-gh-sync-id: a05a9ea9ae8c150ff0714e106410e094c2747eca
shipit-source-id: a05a9ea9ae8c150ff0714e106410e094c2747eca
  • Loading branch information
holmesal authored and facebook-github-bot-7 committed Feb 19, 2016
1 parent 78a9125 commit 183d6a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Libraries/PushNotificationIOS/PushNotificationIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class PushNotificationIOS {
* details is an object containing:
*
* - `alertBody` : The message displayed in the notification alert.
* - `alertAction` : The "action" displayed beneath an actionable notification. Defaults to "view";
* - `soundName` : The sound played when the notification is fired (optional).
* - `category` : The category of this notification, required for actionable notifications (optional).
* - `userInfo` : An optional object containing additional notification data.
*/
static presentLocalNotification(details: Object) {
RCTPushNotificationManager.presentLocalNotification(details);
Expand All @@ -92,7 +95,9 @@ class PushNotificationIOS {
*
* - `fireDate` : The date and time when the system should deliver the notification.
* - `alertBody` : The message displayed in the notification alert.
* - `alertAction` : The "action" displayed beneath an actionable notification. Defaults to "view";
* - `soundName` : The sound played when the notification is fired (optional).
* - `category` : The category of this notification, required for actionable notifications (optional).
* - `userInfo` : An optional object containing additional notification data.
*/
static scheduleLocalNotification(details: Object) {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/PushNotificationIOS/RCTPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ + (UILocalNotification *)UILocalNotification:(id)json
UILocalNotification *notification = [UILocalNotification new];
notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date];
notification.alertBody = [RCTConvert NSString:details[@"alertBody"]];
notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];
notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
notification.category = [RCTConvert NSString:details[@"category"]];
return notification;
}

Expand Down

0 comments on commit 183d6a0

Please sign in to comment.