Explorar el Código

Add notificationCenter setting check

Mathieu Acthernoene hace 5 años
padre
commit
49a0a02911
Se han modificado 4 ficheros con 37 adiciones y 60 borrados
  1. 4
    2
      README.md
  2. 19
    55
      example/App.tsx
  3. 12
    2
      ios/Notifications/RNPermissionHandlerNotifications.m
  4. 2
    1
      src/index.ts

+ 4
- 2
README.md Ver fichero

@@ -268,7 +268,8 @@ interface NotificationSettings {
268 268
   sound?: boolean;
269 269
   lockScreen?: boolean;
270 270
   carPlay?: boolean;
271
-  critical?: boolean;
271
+  notificationCenter?: boolean;
272
+  criticalAlert?: boolean;
272 273
 }
273 274
 
274 275
 function checkNotifications(): Promise<{
@@ -309,7 +310,8 @@ interface NotificationSettings {
309 310
   sound?: boolean;
310 311
   lockScreen?: boolean;
311 312
   carPlay?: boolean;
312
-  critical?: boolean;
313
+  notificationCenter?: boolean;
314
+  criticalAlert?: boolean;
313 315
 }
314 316
 
315 317
 function requestNotifications(

+ 19
- 55
example/App.tsx Ver fichero

@@ -68,6 +68,14 @@ interface State {
68 68
   notifications: NotificationsResponse;
69 69
 }
70 70
 
71
+function getSettingString(setting: boolean | undefined) {
72
+  return setting
73
+    ? RESULTS.GRANTED
74
+    : setting === false
75
+    ? RESULTS.DENIED
76
+    : RESULTS.UNAVAILABLE;
77
+}
78
+
71 79
 export default class App extends React.Component<{}, State> {
72 80
   state: State = {
73 81
     statuses: [],
@@ -91,15 +99,9 @@ export default class App extends React.Component<{}, State> {
91 99
 
92 100
   render() {
93 101
     const {notifications} = this.state;
102
+    const {settings} = notifications;
94 103
 
95
-    const {
96
-      alert,
97
-      badge,
98
-      sound,
99
-      lockScreen,
100
-      carPlay,
101
-      critical,
102
-    } = notifications.settings;
104
+    console.warn(settings);
103 105
 
104 106
     return (
105 107
       <View style={{flex: 1, backgroundColor: theme.colors.background}}>
@@ -167,53 +169,15 @@ export default class App extends React.Component<{}, State> {
167 169
         </TouchableRipple>
168 170
 
169 171
         <Text style={{margin: 15, marginTop: 0, color: '#777'}}>
170
-          {`alert: ${
171
-            alert
172
-              ? RESULTS.GRANTED
173
-              : alert === false
174
-              ? RESULTS.DENIED
175
-              : RESULTS.UNAVAILABLE
176
-          }\n`}
177
-
178
-          {`badge: ${
179
-            badge
180
-              ? RESULTS.GRANTED
181
-              : badge === false
182
-              ? RESULTS.DENIED
183
-              : RESULTS.UNAVAILABLE
184
-          }\n`}
185
-
186
-          {`sound: ${
187
-            sound
188
-              ? RESULTS.GRANTED
189
-              : sound === false
190
-              ? RESULTS.DENIED
191
-              : RESULTS.UNAVAILABLE
192
-          }\n`}
193
-
194
-          {`lockScreen: ${
195
-            lockScreen
196
-              ? RESULTS.GRANTED
197
-              : lockScreen === false
198
-              ? RESULTS.DENIED
199
-              : RESULTS.UNAVAILABLE
200
-          }\n`}
201
-
202
-          {`carPlay: ${
203
-            carPlay
204
-              ? RESULTS.GRANTED
205
-              : carPlay === false
206
-              ? RESULTS.DENIED
207
-              : RESULTS.UNAVAILABLE
208
-          }\n`}
209
-
210
-          {`critical: ${
211
-            critical
212
-              ? RESULTS.GRANTED
213
-              : critical === false
214
-              ? RESULTS.DENIED
215
-              : RESULTS.UNAVAILABLE
216
-          }\n`}
172
+          {`alert: ${getSettingString(settings.alert)}\n`}
173
+          {`badge: ${getSettingString(settings.badge)}\n`}
174
+          {`sound: ${getSettingString(settings.sound)}\n`}
175
+          {`lockScreen: ${getSettingString(settings.lockScreen)}\n`}
176
+          {`notificationCenter: ${getSettingString(
177
+            settings.notificationCenter,
178
+          )}\n`}
179
+          {`carPlay: ${getSettingString(settings.carPlay)}\n`}
180
+          {`criticalAlert: ${getSettingString(settings.criticalAlert)}\n`}
217 181
         </Text>
218 182
       </View>
219 183
     );

+ 12
- 2
ios/Notifications/RNPermissionHandlerNotifications.m Ver fichero

@@ -27,6 +27,7 @@
27 27
       bool sound = settings.soundSetting == UNNotificationSettingEnabled;
28 28
       bool lockScreen = settings.lockScreenSetting == UNNotificationSettingEnabled;
29 29
       bool carPlay = settings.carPlaySetting == UNNotificationSettingEnabled;
30
+      bool notificationCenter = settings.notificationCenterSetting == UNNotificationSettingEnabled;
30 31
 
31 32
       if (settings.alertSetting != UNNotificationSettingNotSupported)
32 33
         [result setValue:@(alert) forKey:@"alert"];
@@ -38,6 +39,8 @@
38 39
         [result setValue:@(lockScreen) forKey:@"lockScreen"];
39 40
       if (settings.carPlaySetting != UNNotificationSettingNotSupported)
40 41
         [result setValue:@(carPlay) forKey:@"carPlay"];
42
+      if (settings.notificationCenterSetting != UNNotificationSettingNotSupported)
43
+        [result setValue:@(notificationCenter) forKey:@"notificationCenter"];
41 44
 
42 45
       if (@available(iOS 12.0, *)) {
43 46
         bool criticalAlert = settings.criticalAlertSetting == UNNotificationSettingEnabled;
@@ -104,7 +107,12 @@
104 107
       if (provisional) types += UNAuthorizationOptionProvisional;
105 108
     }
106 109
 
107
-    if (!alert && !badge && !sound && !criticalAlert && !carPlay && !provisional) {
110
+    if (!alert &&
111
+        !badge &&
112
+        !sound &&
113
+        !criticalAlert &&
114
+        !carPlay &&
115
+        !provisional) {
108 116
       types += UNAuthorizationOptionAlert;
109 117
       types += UNAuthorizationOptionBadge;
110 118
       types += UNAuthorizationOptionSound;
@@ -135,7 +143,9 @@
135 143
       if (badge) types += UIUserNotificationTypeBadge;
136 144
       if (sound) types += UIUserNotificationTypeSound;
137 145
 
138
-      if (!alert && !badge && !sound) {
146
+      if (!alert &&
147
+          !badge &&
148
+          !sound) {
139 149
         types += UIUserNotificationTypeAlert;
140 150
         types += UIUserNotificationTypeBadge;
141 151
         types += UIUserNotificationTypeSound;

+ 2
- 1
src/index.ts Ver fichero

@@ -88,7 +88,8 @@ export interface NotificationSettings {
88 88
   sound?: boolean;
89 89
   lockScreen?: boolean;
90 90
   carPlay?: boolean;
91
-  critical?: boolean;
91
+  notificationCenter?: boolean;
92
+  criticalAlert?: boolean;
92 93
 }
93 94
 
94 95
 export interface NotificationsResponse {