From dd8ed629a5ec2215e24b104dee45bef3fb08dc61 Mon Sep 17 00:00:00 2001 From: James Timmons Date: Mon, 5 Jun 2017 17:48:49 -0700 Subject: [PATCH] Expose category property of iOS notifications Summary: Thanks for submitting a PR! Please read these instructions carefully: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. - [x] Match the **code formatting** of the rest of the codebase. - [x] Target the `master` branch, NOT a "stable" branch. This change allows app code to access the 'category' property of incoming iOS remote push notifications. Currently the property is not made available. Create a test application which: - registers for remote notifications with APNs - passes the returned token to your push notification service provider - displays the contents of the notification, including the 'category' Send a remote push notification including a value for the category property in the payload. Check that the category is displayed in the application. I considered updating RNTester but I couldn't for the life of me figure out how to get it to compile on my machine, sorry ;-) I can confirm my change works when applied directly in the node_modules of an existing RN project. I've signed the CLA. Hope this is enough info to go on, please let me know if not! Closes https://github.com/facebook/react-native/pull/14322 Differential Revision: D5184941 Pulled By: javache fbshipit-source-id: b69decedafac37a5212efcf32faf858aa67ed691 --- Libraries/PushNotificationIOS/PushNotificationIOS.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Libraries/PushNotificationIOS/PushNotificationIOS.js b/Libraries/PushNotificationIOS/PushNotificationIOS.js index 6a511d5f51f..2ece66e2f6b 100644 --- a/Libraries/PushNotificationIOS/PushNotificationIOS.js +++ b/Libraries/PushNotificationIOS/PushNotificationIOS.js @@ -121,6 +121,7 @@ class PushNotificationIOS { _data: Object; _alert: string | Object; _sound: string; + _category: string; _badgeCount: number; _notificationId: string; _isRemote: boolean; @@ -417,6 +418,7 @@ class PushNotificationIOS { this._alert = notifVal.alert; this._sound = notifVal.sound; this._badgeCount = notifVal.badge; + this._category = notifVal.category; } else { this._data[notifKey] = notifVal; } @@ -427,6 +429,7 @@ class PushNotificationIOS { this._sound = nativeNotif.soundName; this._alert = nativeNotif.alertBody; this._data = nativeNotif.userInfo; + this._category = nativeNotif.category; } } @@ -467,6 +470,13 @@ class PushNotificationIOS { return this._sound; } + /** + * Gets the category string from the `aps` object + */ + getCategory(): ?string { + return this._category; + } + /** * Gets the notification's main message from the `aps` object */