From 84e696867b848f98296b6db5d6b112319421b5f8 Mon Sep 17 00:00:00 2001 From: alvaromb Date: Fri, 29 Apr 2016 05:36:08 -0700 Subject: [PATCH] Added badge icon number and alert action Summary: Added support for setting an optional badge icon number and alert action when using local notifications. Closes https://github.com/facebook/react-native/pull/2931 Differential Revision: D3212448 Pulled By: mkonicek fb-gh-sync-id: 063efcdd259b2a43f39812f57a71e8489ab33653 fbshipit-source-id: 063efcdd259b2a43f39812f57a71e8489ab33653 --- Libraries/PushNotificationIOS/PushNotificationIOS.js | 2 ++ Libraries/PushNotificationIOS/RCTPushNotificationManager.m | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Libraries/PushNotificationIOS/PushNotificationIOS.js b/Libraries/PushNotificationIOS/PushNotificationIOS.js index 264f40f3ebdfdd..39fbca8c654876 100644 --- a/Libraries/PushNotificationIOS/PushNotificationIOS.js +++ b/Libraries/PushNotificationIOS/PushNotificationIOS.js @@ -83,6 +83,7 @@ class PushNotificationIOS { * - `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. + * - `applicationIconBadgeNumber` (optional) : The number to display as the app’s icon badge. The default value of this property is 0, which means that no badge is displayed. */ static presentLocalNotification(details: Object) { RCTPushNotificationManager.presentLocalNotification(details); @@ -99,6 +100,7 @@ class PushNotificationIOS { * - `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. + * - `applicationIconBadgeNumber` (optional) : The number to display as the app’s icon badge. Setting the number to 0 removes the icon badge. */ static scheduleLocalNotification(details: Object) { RCTPushNotificationManager.scheduleLocalNotification(details); diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m index 5dd5b4774464cc..b9df76865f3647 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m @@ -40,6 +40,9 @@ + (UILocalNotification *)UILocalNotification:(id)json notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName; notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]]; notification.category = [RCTConvert NSString:details[@"category"]]; + if (details[@"applicationIconBadgeNumber"]) { + notification.applicationIconBadgeNumber = [RCTConvert NSInteger:details[@"applicationIconBadgeNumber"]]; + } return notification; }