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
This commit is contained in:
Tina J 2017-08-06 20:16:04 -07:00 committed by Facebook Github Bot
parent b2fe048a0b
commit ec74a9696a
2 changed files with 2 additions and 0 deletions

View File

@ -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).

View File

@ -53,6 +53,7 @@ RCT_ENUM_CONVERTER(NSCalendarUnit,
NSDictionary<NSString *, id> *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"]];