From 183d6a088cbc13f5e123a54cbe63430d92450e96 Mon Sep 17 00:00:00 2001 From: Alonso Holmes Date: Fri, 19 Feb 2016 05:18:24 -0800 Subject: [PATCH] Adds category and alertAction properties to local notification details 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 https://github.com/facebook/react-native/pull/5994 Differential Revision: D2953919 Pulled By: nicklockwood fb-gh-sync-id: a05a9ea9ae8c150ff0714e106410e094c2747eca shipit-source-id: a05a9ea9ae8c150ff0714e106410e094c2747eca --- Libraries/PushNotificationIOS/PushNotificationIOS.js | 5 +++++ Libraries/PushNotificationIOS/RCTPushNotificationManager.m | 2 ++ 2 files changed, 7 insertions(+) diff --git a/Libraries/PushNotificationIOS/PushNotificationIOS.js b/Libraries/PushNotificationIOS/PushNotificationIOS.js index a4adace18..c93f644a4 100644 --- a/Libraries/PushNotificationIOS/PushNotificationIOS.js +++ b/Libraries/PushNotificationIOS/PushNotificationIOS.js @@ -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); @@ -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) { diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m index e9c68a5ec..86c9a37ad 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m @@ -36,8 +36,10 @@ NSString *const RCTRemoteNotificationsRegistered = @"RemoteNotificationsRegister 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; }