mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
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:
.
|
||||
* - `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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user