7
7
8
8
React Native Push Notification API for iOS.
9
9
10
+ | Notification | With Action | With TextInput Action |
11
+ | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
12
+ | <img src =" https://user-images.githubusercontent.com/6936373/97115527-77c6ee80-173a-11eb-8440-049590a25f31.jpeg " width =" 320 " /> | <img src =" https://user-images.githubusercontent.com/6936373/97115526-772e5800-173a-11eb-8b51-c5263bced07a.jpeg " width =" 320 " /> | <img src =" https://user-images.githubusercontent.com/6936373/97115522-74cbfe00-173a-11eb-9644-fc1d5e634d6b.jpeg " width =" 320 " /> |
13
+
10
14
## Getting started
11
15
12
16
### Install
@@ -116,14 +120,7 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
116
120
withCompletionHandler:(void (^)(void ))completionHandler
117
121
{
118
122
[ RNCPushNotificationIOS didReceiveNotificationResponse: response ] ;
119
- completionHandler ();
120
- }
121
- // IOS 4-10 Required for the localNotification event.
122
- - (void )application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
123
- {
124
- [ RNCPushNotificationIOS didReceiveLocalNotification: notification ] ;
125
123
}
126
-
127
124
```
128
125
129
126
And then in your AppDelegate implementation, add the following:
@@ -184,6 +181,57 @@ export const App = () => {
184
181
};
185
182
```
186
183
184
+ ## How to perform different action based on user selected action.
185
+
186
+ ``` js
187
+ export const App = () => {
188
+ const [permissions , setPermissions ] = useState ({});
189
+
190
+ /**
191
+ * By calling this function, notification with category `userAction` will have action buttons
192
+ */
193
+ const setNotificationCategories = () => {
194
+ PushNotificationIOS .setNotificationCategories ([
195
+ {
196
+ id: ' userAction' ,
197
+ actions: [
198
+ {id: ' open' , title: ' Open' , options: {foreground: true }},
199
+ {
200
+ id: ' ignore' ,
201
+ title: ' Desruptive' ,
202
+ options: {foreground: true , destructive: true },
203
+ },
204
+ {
205
+ id: ' text' ,
206
+ title: ' Text Input' ,
207
+ options: {foreground: true },
208
+ textInput: {buttonTitle: ' Send' },
209
+ },
210
+ ],
211
+ },
212
+ ]);
213
+ };
214
+
215
+ useEffect (() => {
216
+ PushNotificationIOS .addEventListener (' notification' , onRemoteNotification);
217
+ });
218
+
219
+ const onRemoteNotification = (notification ) => {
220
+ const actionIdentifier = notification .getActionIdentifier ();
221
+
222
+ if (actionIdentifier === ' open' ) {
223
+ // Perform action based on open action
224
+ }
225
+
226
+ if (actionIdentifier === ' text' ) {
227
+ // Text that of user input.
228
+ const userText = notification .getUserText ();
229
+ // Perform action based on textinput action
230
+ }
231
+ };
232
+ };
233
+ ```
234
+
187
235
# Reference
188
236
189
237
## Methods
@@ -194,6 +242,7 @@ export const App = () => {
194
242
PushNotificationIOS .presentLocalNotification (details);
195
243
```
196
244
245
+ _ Deprecated_ - use ` addNotificationRequest ` instead.
197
246
Schedules the localNotification for immediate presentation.
198
247
199
248
** Parameters:**
@@ -221,6 +270,7 @@ details is an object containing:
221
270
PushNotificationIOS .scheduleLocalNotification (details);
222
271
```
223
272
273
+ _ Deprecated_ - use ` addNotificationRequest ` instead.
224
274
Schedules the localNotification for future presentation.
225
275
226
276
** Parameters:**
@@ -244,6 +294,71 @@ details is an object containing:
244
294
245
295
---
246
296
297
+ ### ` addNotificationRequest() `
298
+
299
+ ``` jsx
300
+ PushNotificationIOS .addNotificationRequest (request);
301
+ ```
302
+
303
+ Sends notificationRequest to notification center at specified firedate.
304
+ Fires immediately if firedate is not set.
305
+
306
+ ** Parameters:**
307
+
308
+ | Name | Type | Required | Description |
309
+ | ------- | ------ | -------- | ----------- |
310
+ | request | object | Yes | See below. |
311
+
312
+ request is an object containing:
313
+
314
+ - ` id ` : Identifier of the notification. Required in order to be able to retrieve specific notification. (required)
315
+ - ` title ` : A short description of the reason for the alert.
316
+ - ` subtitle ` : A secondary description of the reason for the alert.
317
+ - ` body ` : The message displayed in the notification alert.
318
+ - ` badge ` The number to display as the app's icon badge. Setting the number to 0 removes the icon badge.
319
+ - ` fireDate ` : The date and time when the system should deliver the notification.
320
+ - ` repeats ` : Sets notification to repeat daily. Must be used with fireDate.
321
+ - ` sound ` : The sound played when the notification is fired.
322
+ - ` category ` : The category of this notification, required for actionable notifications.
323
+ - ` isSilent ` : If true, the notification will appear without sound.
324
+ - ` userInfo ` : An object containing additional notification data.
325
+
326
+ ---
327
+
328
+ ### ` setNotificationCategories() `
329
+
330
+ ``` jsx
331
+ PushNotificationIOS .setNotificationCategories (categories);
332
+ ```
333
+
334
+ Sets category for the notification center.
335
+ Allows you to add specific actions for notification with specific category.
336
+
337
+ ** Parameters:**
338
+
339
+ | Name | Type | Required | Description |
340
+ | ---------- | -------- | -------- | ----------- |
341
+ | categories | object[ ] | Yes | See below. |
342
+
343
+ ` category ` is an object containing:
344
+
345
+ - ` id ` : Identifier of the notification category. Notification with this category will have the specified actions. (required)
346
+ - ` actions ` : An array of notification actions to be attached to the notification of category id.
347
+
348
+ ` action ` is an object containing:
349
+
350
+ - ` id ` : Identifier of Action. This value will be returned as actionIdentifier when notification is received.
351
+ - ` title ` : Text to be shown on notification action button.
352
+ - ` options ` : Options for notification action.
353
+ - ` foreground ` : If ` true ` , action will be displayed on notification.
354
+ - ` destructive ` : If ` true ` , action will be displayed as destructive notification.
355
+ - ` authenticationRequired ` : If ` true ` , action will only be displayed for authenticated user.
356
+ - ` textInput ` : Option for textInput action. If textInput prop exists, then user action will automatically become a text input action. The text user inputs will be in the userText field of the received notification.
357
+ - ` buttonTitle ` : Text to be shown on button when user finishes text input. Default is "Send" or its equivalent word in user's language setting.
358
+ - ` placeholder ` : Placeholder for text input for text input action.
359
+
360
+ ---
361
+
247
362
### ` remooveAllPendingNotificationRequests() `
248
363
249
364
``` jsx
0 commit comments