@@ -203,6 +203,9 @@ const channelImportance = 3; // The channel's importance (NotificationM
203
203
const channelShowBadge = true ;
204
204
const channelEnableLights = true ;
205
205
const channelEnableVibration = true ;
206
+ const template = ' ...' ; // Notification hub templates:
207
+ // https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-templates-cross-platform-push-messages
208
+ const templateName = ' ...' ; // The template's name
206
209
207
210
export default class App extends Component {
208
211
constructor (props ) {
@@ -213,7 +216,7 @@ export default class App extends Component {
213
216
register () {
214
217
PushNotificationEmitter .addListener (EVENT_AZURE_NOTIFICATION_HUB_REGISTERED , this ._onAzureNotificationHubRegistered );
215
218
PushNotificationEmitter .addListener (EVENT_AZURE_NOTIFICATION_HUB_REGISTERED_ERROR , this ._onAzureNotificationHubRegisteredError );
216
-
219
+
217
220
NotificationHub .register ({
218
221
connectionString,
219
222
hubName,
@@ -225,12 +228,59 @@ export default class App extends Component {
225
228
channelEnableLights,
226
229
channelEnableVibration
227
230
})
231
+ .then ((res ) => console .warn (res))
232
+ .catch (reason => console .warn (reason));
233
+ }
234
+
235
+ registerTemplate () {
236
+ PushNotificationEmitter .addListener (EVENT_AZURE_NOTIFICATION_HUB_REGISTERED , this ._onAzureNotificationHubRegistered );
237
+ PushNotificationEmitter .addListener (EVENT_AZURE_NOTIFICATION_HUB_REGISTERED_ERROR , this ._onAzureNotificationHubRegisteredError );
238
+
239
+ NotificationHub .registerTemplate ({
240
+ connectionString,
241
+ hubName,
242
+ senderID,
243
+ template,
244
+ templateName,
245
+ tags,
246
+ channelName,
247
+ channelImportance,
248
+ channelShowBadge,
249
+ channelEnableLights,
250
+ channelEnableVibration
251
+ })
252
+ .then ((res ) => console .warn (res))
253
+ .catch (reason => console .warn (reason));
254
+ }
255
+
256
+ getInitialNotification () {
257
+ NotificationHub .getInitialNotification ()
258
+ .then ((res ) => console .warn (res))
259
+ .catch (reason => console .warn (reason));
260
+ }
261
+
262
+ getUUID () {
263
+ NotificationHub .getUUID (false )
264
+ .then ((res ) => console .warn (res))
265
+ .catch (reason => console .warn (reason));
266
+ }
267
+
268
+ isNotificationEnabledOnOSLevel () {
269
+ NotificationHub .isNotificationEnabledOnOSLevel ()
270
+ .then ((res ) => console .warn (res))
228
271
.catch (reason => console .warn (reason));
229
272
}
230
273
231
274
unregister () {
232
275
NotificationHub .unregister ()
233
- .catch (reason => console .warn (reason));
276
+ .then ((res ) => console .warn (res))
277
+ .catch (reason => console .warn (reason));
278
+ }
279
+
280
+ unregisterTemplate () {
281
+ NotificationHub .unregisterTemplate (templateName)
282
+ .then ((res ) => console .warn (res))
283
+ .catch (reason => console .warn (reason));
234
284
}
235
285
236
286
render () {
@@ -240,28 +290,63 @@ export default class App extends Component {
240
290
< View style= {styles .button }>
241
291
< Text style= {styles .buttonText }>
242
292
Register
243
- < / Text >
293
+ < / Text >
294
+ < / View>
295
+ < / TouchableOpacity>
296
+ < TouchableOpacity onPress= {this .registerTemplate .bind (this )}>
297
+ < View style= {styles .button }>
298
+ < Text style= {styles .buttonText }>
299
+ Register Template
300
+ < / Text >
301
+ < / View>
302
+ < / TouchableOpacity>
303
+ < TouchableOpacity onPress= {this .getInitialNotification .bind (this )}>
304
+ < View style= {styles .button }>
305
+ < Text style= {styles .buttonText }>
306
+ Get initial notification
307
+ < / Text >
308
+ < / View>
309
+ < / TouchableOpacity>
310
+ < TouchableOpacity onPress= {this .getUUID .bind (this )}>
311
+ < View style= {styles .button }>
312
+ < Text style= {styles .buttonText }>
313
+ Get UUID
314
+ < / Text >
315
+ < / View>
316
+ < / TouchableOpacity>
317
+ < TouchableOpacity onPress= {this .isNotificationEnabledOnOSLevel .bind (this )}>
318
+ < View style= {styles .button }>
319
+ < Text style= {styles .buttonText }>
320
+ Check if notification is enabled
321
+ < / Text >
244
322
< / View>
245
323
< / TouchableOpacity>
246
324
< TouchableOpacity onPress= {this .unregister .bind (this )}>
247
325
< View style= {styles .button }>
248
326
< Text style= {styles .buttonText }>
249
327
Unregister
250
- < / Text >
328
+ < / Text >
329
+ < / View>
330
+ < / TouchableOpacity>
331
+ < TouchableOpacity onPress= {this .unregisterTemplate .bind (this )}>
332
+ < View style= {styles .button }>
333
+ < Text style= {styles .buttonText }>
334
+ Unregister Template
335
+ < / Text >
251
336
< / View>
252
337
< / TouchableOpacity>
253
338
< / View>
254
339
);
255
340
}
256
-
341
+
257
342
_onAzureNotificationHubRegistered (registrationID ) {
258
343
console .warn (' RegistrationID: ' + registrationID);
259
344
}
260
-
345
+
261
346
_onAzureNotificationHubRegisteredError (error ) {
262
347
console .warn (' Error: ' + error);
263
348
}
264
-
349
+
265
350
_onRemoteNotification (notification ) {
266
351
console .warn (notification);
267
352
}
0 commit comments