@@ -14,15 +14,69 @@ module FetchResult = {
14
14
external resultFailed : t = "ResultFailed" ;
15
15
};
16
16
17
+ /**
18
+ * Alert Object that can be included in the aps `alert` object
19
+ */
20
+ type notificationAlert = {
21
+ title: option (string ),
22
+ subtitle: option (string ),
23
+ body: option (string ),
24
+ };
25
+
26
+ type notificationActionOptions = {
27
+ foreground: option (bool ),
28
+ destructive: option (bool ),
29
+ authenticationRequired: option (bool ),
30
+ };
31
+
32
+ type notificationActionTextInput = {
33
+ /**
34
+ * Text to be shown on button when user finishes text input.
35
+ * Default is "Send" or its equivalent word in user's language setting.
36
+ */
37
+ buttonTitle: option (string ),
38
+ /**
39
+ * Placeholder for text input for text input action.
40
+ */
41
+ placeholder: option (string ),
42
+ };
43
+
44
+ /**
45
+ * Notification Action that can be added to specific categories
46
+ */
47
+ type notificationAction = {
48
+ /**
49
+ * Id of Action.
50
+ * This value will be returned as actionIdentifier when notification is received.
51
+ */
52
+ id: string ,
53
+ /**
54
+ * Text to be shown on notification action button.
55
+ */
56
+ title: string ,
57
+ /**
58
+ * Option for notification action.
59
+ */
60
+ options: option (notificationActionOptions ),
61
+ /**
62
+ * Option for textInput action.
63
+ * If textInput prop exists, then user action will automatically become a text input action.
64
+ * The text user inputs will be in the userText field of the received notification.
65
+ */
66
+ textInput: option (notificationActionTextInput ),
67
+ };
68
+
17
69
module Notification = {
18
70
type t ;
19
71
20
72
[@ bs . send ] [@ bs . return nullable]
73
+ // string | notificationAlert
21
74
external getAlert : t => option (Js . Json . t ) = "getAlert" ;
22
75
23
76
[@ bs . send ] external getTitle : t => string = "getTitle" ;
24
77
25
78
[@ bs . send ] [@ bs . return nullable]
79
+ // string | notificationAlert
26
80
external getMessage : t => option (Js . Json . t ) = "getMessage" ;
27
81
28
82
[@ bs . send ] [@ bs . return nullable]
@@ -40,12 +94,101 @@ module Notification = {
40
94
[@ bs . send ] [@ bs . return nullable]
41
95
external getData : t => option (Js . Json . t ) = "getData" ;
42
96
97
+ /**
98
+ * Get's the action id of the notification action user has taken.
99
+ */
100
+ [@ bs . send ] [@ bs . return nullable]
101
+ external getActionIdentifier : t => option (string ) = "getActionIdentifier" ;
102
+
103
+ /**
104
+ * Gets the text user has inputed if user has taken the text action response.
105
+ */
106
+ [@ bs . send ] [@ bs . return nullable]
107
+ external getUserText : t => option (string ) = "getUserText" ;
108
+
43
109
[@ bs . send ] [@ bs . return nullable]
44
110
external getThreadID : t => option (string ) = "getThreadID" ;
45
111
46
112
[@ bs . send ] external finish : (t , FetchResult . t ) => unit = "finish" ;
47
113
};
48
114
115
+ type notificationRequest = {
116
+ /**
117
+ * identifier of the notification.
118
+ * Required in order to retrieve specific notification.
119
+ */
120
+ id: string ,
121
+ /**
122
+ * A short description of the reason for the alert.
123
+ */
124
+ title: option (string ),
125
+ /**
126
+ * A secondary description of the reason for the alert.
127
+ */
128
+ subtitle: option (string ),
129
+ /**
130
+ * The message displayed in the notification alert.
131
+ */
132
+ body: option (string ),
133
+ /**
134
+ * The number to display as the app's icon badge.
135
+ */
136
+ badge: option (int ),
137
+ /**
138
+ * The sound to play when the notification is delivered.
139
+ */
140
+ sound: option (string ),
141
+ /**
142
+ * The category of this notification. Required for actionable notifications.
143
+ */
144
+ category: option (string ),
145
+ /**
146
+ * The thread identifier of this notification.
147
+ */
148
+ threadId: option (string ),
149
+ /**
150
+ * The date which notification triggers.
151
+ */
152
+ fireDate: option (Js . Date . t ),
153
+ /**
154
+ * Sets notification to repeat daily.
155
+ * Must be used with fireDate.
156
+ */
157
+ repeats: option (bool ),
158
+ /**
159
+ * Sets notification to be silent
160
+ */
161
+ isSilent: option (bool ),
162
+ /**
163
+ * Optional data to be added to the notification
164
+ */
165
+ userInfo: option (Js . Json . t ),
166
+ };
167
+
168
+ [@ bs . obj ]
169
+ external notificationRequest :
170
+ (
171
+ ~id : string ,
172
+ ~title : string =?,
173
+ ~subtitle : string =?,
174
+ ~body : string =?,
175
+ ~badge : int =?,
176
+ ~sound : string =?,
177
+ ~category : string =?,
178
+ ~threadId : string =?,
179
+ ~fireDate : Js . Date . t =?,
180
+ ~repeats : bool =?,
181
+ ~isSilent : bool =?,
182
+ ~userInfo : Js . Json . t =?,
183
+ unit
184
+ ) =>
185
+ notificationRequest ;
186
+
187
+ [@ bs . module "@react-native-community/push-notification-ios" ]
188
+ [@ bs . scope "default" ]
189
+ external addNotificationRequest : notificationRequest => unit =
190
+ "addNotificationRequest" ;
191
+
49
192
type localNotification ;
50
193
51
194
[@ bs . obj ]
@@ -65,21 +208,29 @@ external localNotification:
65
208
) =>
66
209
localNotification ;
67
210
211
+ [@ deprecated "Please use addNotificationRequest instead" ]
68
212
[@ bs . module "@react-native-community/push-notification-ios" ]
69
213
[@ bs . scope "default" ]
70
214
external presentLocalNotification : localNotification => unit =
71
215
"presentLocalNotification" ;
72
216
217
+ [@ deprecated "Please use addNotificationRequest instead" ]
73
218
[@ bs . module "@react-native-community/push-notification-ios" ]
74
219
[@ bs . scope "default" ]
75
220
external scheduleLocalNotification : localNotification => unit =
76
221
"scheduleLocalNotification" ;
77
222
223
+ [@ deprecated "Please use removeAllPendingNotificationRequests instead" ]
78
224
[@ bs . module "@react-native-community/push-notification-ios" ]
79
225
[@ bs . scope "default" ]
80
226
external cancelAllLocalNotifications : unit => unit =
81
227
"cancelAllLocalNotifications" ;
82
228
229
+ [@ bs . module "@react-native-community/push-notification-ios" ]
230
+ [@ bs . scope "default" ]
231
+ external removeAllPendingNotificationRequests : unit => unit =
232
+ "removeAllPendingNotificationRequests" ;
233
+
83
234
[@ bs . module "@react-native-community/push-notification-ios" ]
84
235
[@ bs . scope "default" ]
85
236
external removeAllDeliveredNotifications : unit => unit =
@@ -89,10 +240,13 @@ type deliveredNotification = {
89
240
identifier: string ,
90
241
date: option (string ),
91
242
title: option (string ),
243
+ subtitle: option (string ),
92
244
body: option (string ),
93
245
category: option (string ),
246
+ actionIdentifier: option (string ),
94
247
[@bs.as "thread-id"]
95
248
threadId: option (string ),
249
+ userText: option (string ),
96
250
userInfo: option (Js . Json . t ),
97
251
};
98
252
@@ -140,12 +294,19 @@ type formattedLocalNotification = {
140
294
userInfo: option (Js . Json . t ),
141
295
};
142
296
297
+ [@ deprecated "Please use getPendingNotificationRequests instead" ]
143
298
[@ bs . module "@react-native-community/push-notification-ios" ]
144
299
[@ bs . scope "default" ]
145
300
external getScheduledLocalNotifications :
146
301
(array (formattedLocalNotification ) => unit ) => unit =
147
302
"getScheduledLocalNotifications" ;
148
303
304
+ [@ bs . module "@react-native-community/push-notification-ios" ]
305
+ [@ bs . scope "default" ]
306
+ external getPendingNotificationRequests :
307
+ (array (notificationRequest ) => unit ) => unit =
308
+ "getPendingNotificationRequests" ;
309
+
149
310
type registrationError (' a ) = {
150
311
message: string,
151
312
code: int,
@@ -182,12 +343,20 @@ external removeEventListener:
182
343
unit =
183
344
"removeEventListener" ;
184
345
185
- type permissions = {
346
+ type requestedPermissions = {
347
+ alert: bool ,
348
+ badge: bool ,
349
+ sound: bool ,
350
+ };
351
+
352
+ type checkedPermissions = {
186
353
alert: bool ,
187
354
badge: bool ,
188
355
sound: bool ,
189
356
lockScreen: bool ,
190
357
notificationCenter: bool ,
358
+ // https://developer.apple.com/documentation/usernotifications/unauthorizationstatus
359
+ authorizationStatus: int ,
191
360
};
192
361
193
362
type requestPermissionsOptions ;
@@ -199,14 +368,14 @@ external requestPermissionsOptions:
199
368
// multiple externals
200
369
[@ bs . module "@react-native-community/push-notification-ios" ]
201
370
[@ bs . scope "default" ]
202
- external requestPermissions : unit => Js . Promise . t (permissions ) =
371
+ external requestPermissions : unit => Js . Promise . t (requestedPermissions ) =
203
372
"requestPermissions" ;
204
373
205
374
// multiple externals
206
375
[@ bs . module "@react-native-community/push-notification-ios" ]
207
376
[@ bs . scope "default" ]
208
377
external requestPermissionsWithOptions :
209
- requestPermissionsOptions => Js . Promise . t (permissions ) =
378
+ requestPermissionsOptions => Js . Promise . t (requestedPermissions ) =
210
379
"requestPermissions" ;
211
380
212
381
[@ bs . module "@react-native-community/push-notification-ios" ]
@@ -215,10 +384,24 @@ external abandonPermissions: unit => unit = "abandonPermissions";
215
384
216
385
[@ bs . module "@react-native-community/push-notification-ios" ]
217
386
[@ bs . scope "default" ]
218
- external checkPermissions : (unit => permissions ) => unit = "checkPermissions" ;
387
+ external checkPermissions : (unit => checkedPermissions ) => unit =
388
+ "checkPermissions" ;
219
389
220
390
[@ bs . module "@react-native-community/push-notification-ios" ]
221
391
[@ bs . scope "default" ]
222
392
external getInitialNotification :
223
393
unit => Js . Promise . t (Js . Nullable . t (Notification . t )) =
224
394
"getInitialNotification" ;
395
+
396
+ /**
397
+ * Notification Category that can include specific actions
398
+ */
399
+ type notificationCategory = {
400
+ id: string ,
401
+ actions: array (notificationAction ),
402
+ };
403
+ [@ bs . module "@react-native-community/push-notification-ios" ]
404
+ [@ bs . scope "default" ]
405
+ external setNotificationCategories :
406
+ array (notificationCategory ) => Js . Promise . t (unit ) =
407
+ "setNotificationCategories" ;
0 commit comments