From ec74a9696a8864928cab59e40db8b446deb23762 Mon Sep 17 00:00:00 2001 From: Tina J Date: Sun, 6 Aug 2017 20:16:04 -0700 Subject: [PATCH] Set alertTitle in UILocalNotification Summary: Currently, since the alertTitle is not set in UILocalNotification, the notification displays just the notification body with no title. This commit sets the alertTitle for local notifications. Issue: #14699 - In a sample RN app, created a component and added the following code to componentDidMount(): `PushNotificationIOS.scheduleLocalNotification({ fireDate: new Date(Date.now() + (30 * 1000)).toISOString(), alertTitle: 'Incoming Message', alertBody: 'Test message', soundName: 'default' })` - On running the app, the notification appears with both body and title once the component is mounted. ![settitle_fix](https://user-images.githubusercontent.com/4279549/28995873-f62c9866-7a11-11e7-9f29-95dba50ef40b.jpg) Closes https://github.com/facebook/react-native/pull/15381 Differential Revision: D5572606 Pulled By: shergin fbshipit-source-id: ce5d98ed595eedf51ac3da7dfd94de52cf80be3d --- Libraries/PushNotificationIOS/PushNotificationIOS.js | 1 + Libraries/PushNotificationIOS/RCTPushNotificationManager.m | 1 + 2 files changed, 2 insertions(+) diff --git a/Libraries/PushNotificationIOS/PushNotificationIOS.js b/Libraries/PushNotificationIOS/PushNotificationIOS.js index d5dc474b9..8b738b6e6 100644 --- a/Libraries/PushNotificationIOS/PushNotificationIOS.js +++ b/Libraries/PushNotificationIOS/PushNotificationIOS.js @@ -159,6 +159,7 @@ class PushNotificationIOS { * details is an object containing: * * - `fireDate` : The date and time when the system should deliver the notification. + * - `alertTitle` : The text displayed as the title of the notification alert. * - `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). diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m index 29656e01a..aeb8af202 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m @@ -53,6 +53,7 @@ RCT_ENUM_CONVERTER(NSCalendarUnit, NSDictionary *details = [self NSDictionary:json]; BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]]; UILocalNotification *notification = [UILocalNotification new]; + notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]]; notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date]; notification.alertBody = [RCTConvert NSString:details[@"alertBody"]]; notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];