Skip to content

Commit c79520b

Browse files
committed
Updated code samples, grammar nitpicks, note on tags
1 parent c835a01 commit c79520b

File tree

3 files changed

+101
-78
lines changed

3 files changed

+101
-78
lines changed

docs/android-installation.md

+52-35
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ On the [Azure Portal](https://portal.azure.com) page for your notification hub,
171171

172172
![Get Connection String](img/GetConnectionString.png)
173173

174-
The example below shows how you can register and unregister from Azure Notification Hub in your React component.
174+
The example below shows how you can register and unregister from Azure Notification Hub in your React Native component.
175175

176176
```js
177177
import React, { Component } from 'react';
@@ -193,7 +193,7 @@ const EVENT_REMOTE_NOTIFICATION_RECEIVED = 'remoteNotificationRec
193193
const connectionString = '...'; // The Notification Hub connection string
194194
const hubName = '...'; // The Notification Hub name
195195
const senderID = '...'; // The Sender ID from the Cloud Messaging tab of the Firebase console
196-
const tags = [ ... ]; // The set of tags to subscribe to
196+
const tags = [ '...' ]; // The set of tags to subscribe to. See notes after code sample
197197
const channelName = '...'; // The channel's name (optional)
198198
const channelDescription = '...'; // The channel's description (optional)
199199
const channelImportance = 3; // The channel's importance (NotificationManager.IMPORTANCE_DEFAULT = 3) (optional)
@@ -216,7 +216,7 @@ export default class App extends Component {
216216

217217
register() {
218218
PushNotificationEmitter.addListener(EVENT_AZURE_NOTIFICATION_HUB_REGISTERED, this._onAzureNotificationHubRegistered);
219-
PushNotificationEmitter.addListener(EVENT_AZURE_NOTIFICATION_HUB_REGISTERED_ERROR, this._onAzureNotificationHubRegisteredError);
219+
PushNotificationEmitter.addListener(EVENT_AZURE_NOTIFICATION_HUB_REGISTERED_ERROR, this._onAzureNotificationHubRegistrationError);
220220

221221
NotificationHub.register({
222222
connectionString,
@@ -230,13 +230,13 @@ export default class App extends Component {
230230
channelEnableLights,
231231
channelEnableVibration
232232
})
233-
.then((res) => console.warn(res))
234-
.catch(reason => console.warn(reason));
233+
.then(console.log)
234+
.catch(console.warn);
235235
}
236236

237237
registerTemplate() {
238238
PushNotificationEmitter.addListener(EVENT_AZURE_NOTIFICATION_HUB_REGISTERED, this._onAzureNotificationHubRegistered);
239-
PushNotificationEmitter.addListener(EVENT_AZURE_NOTIFICATION_HUB_REGISTERED_ERROR, this._onAzureNotificationHubRegisteredError);
239+
PushNotificationEmitter.addListener(EVENT_AZURE_NOTIFICATION_HUB_REGISTERED_ERROR, this._onAzureNotificationHubRegistrationError);
240240

241241
NotificationHub.registerTemplate({
242242
connectionString,
@@ -252,38 +252,38 @@ export default class App extends Component {
252252
channelEnableLights,
253253
channelEnableVibration
254254
})
255-
.then((res) => console.warn(res))
256-
.catch(reason => console.warn(reason));
255+
.then(console.log)
256+
.catch(console.warn);
257257
}
258258

259259
getInitialNotification() {
260260
NotificationHub.getInitialNotification()
261-
.then((res) => console.warn(res))
262-
.catch(reason => console.warn(reason));
261+
.then(console.log)
262+
.catch(console.warn);
263263
}
264264

265265
getUUID() {
266266
NotificationHub.getUUID(false)
267-
.then((res) => console.warn(res))
268-
.catch(reason => console.warn(reason));
267+
.then(console.log)
268+
.catch(console.warn);
269269
}
270270

271271
isNotificationEnabledOnOSLevel() {
272272
NotificationHub.isNotificationEnabledOnOSLevel()
273-
.then((res) => console.warn(res))
274-
.catch(reason => console.warn(reason));
273+
.then(console.log)
274+
.catch(console.warn);
275275
}
276276

277277
unregister() {
278278
NotificationHub.unregister()
279-
.then((res) => console.warn(res))
280-
.catch(reason => console.warn(reason));
279+
.then(console.log)
280+
.catch(console.warn);
281281
}
282282

283283
unregisterTemplate() {
284284
NotificationHub.unregisterTemplate(templateName)
285-
.then((res) => console.warn(res))
286-
.catch(reason => console.warn(reason));
285+
.then(console.log)
286+
.catch(console.warn);
287287
}
288288

289289
render() {
@@ -346,7 +346,7 @@ export default class App extends Component {
346346
console.warn('RegistrationID: ' + registrationID);
347347
}
348348

349-
_onAzureNotificationHubRegisteredError(error) {
349+
_onAzureNotificationHubRegistrationError(error) {
350350
console.warn('Error: ' + error);
351351
}
352352

@@ -356,21 +356,38 @@ export default class App extends Component {
356356
}
357357

358358
const styles = StyleSheet.create({
359-
container: {
360-
flex: 1,
361-
justifyContent: 'center',
362-
alignItems: 'center',
363-
backgroundColor: '#F5FCFF',
364-
},
365-
welcome: {
366-
fontSize: 20,
367-
textAlign: 'center',
368-
margin: 10,
369-
},
370-
instructions: {
371-
textAlign: 'center',
372-
color: '#333333',
373-
marginBottom: 5,
374-
},
359+
container: {
360+
flex: 1,
361+
justifyContent: 'center',
362+
alignItems: 'center',
363+
backgroundColor: '#FFF',
364+
},
365+
welcome: {
366+
fontSize: 20,
367+
textAlign: 'center',
368+
margin: 10,
369+
},
370+
instructions: {
371+
textAlign: 'center',
372+
color: '#FFF',
373+
marginBottom: 5,
374+
},
375+
button: {
376+
backgroundColor: '#0071c9',
377+
borderRadius: 4,
378+
justifyContent: 'center',
379+
alignItems: 'center',
380+
padding: 14,
381+
marginVertical: 14,
382+
},
383+
buttonText: {
384+
color: '#FFF',
385+
},
375386
});
376387
```
388+
389+
## A Note On Tags
390+
391+
Azure Notification Hubs uses "tags" to target notifications. To receive targeted notifications, a device subscribes to those tags when registering (they are sent in an array by the `register` and `registerTemplate` methods above). So, if you want to send a notification to one device, that device must register on a unique tag, and report that tag to your backend, where it can be associated with your user. This is a contrast to other notification platforms, which often give you a unique ID during the registration process for this purpose.
392+
393+
Needing to supply your own unique, non-random string (you'll want it again when you unregister the device in your backend) could lead to the temptation to use the device's unique identifier (device ID/UDID) to register for notifications. [There are numerous privacy and security reasons not to do this](https://books.nowsecure.com/secure-mobile-development/en/sensitive-data/limit-use-of-uuid.html).

docs/ios-installation.md

+48-42
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Add the following line to your `ios/Podfile` file and run **pod install**
166166
return YES;
167167
}
168168

169-
// Invoked when the app successfully registered with Apple Push Notification service (APNs).
169+
// Invoked when the app successfully registers with Apple Push Notification service (APNs).
170170
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
171171
{
172172
[RCTAzureNotificationHubManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
@@ -178,15 +178,15 @@ Add the following line to your `ios/Podfile` file and run **pod install**
178178
[RCTAzureNotificationHubManager didFailToRegisterForRemoteNotificationsWithError:error];
179179
}
180180

181-
// Invoked when a remote notification arrived and there is data to be fetched.
181+
// Invoked when a remote notification arrives and there is data to be fetched.
182182
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
183183
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
184184
{
185185
[RCTAzureNotificationHubManager didReceiveRemoteNotification:userInfo
186186
fetchCompletionHandler:completionHandler];
187187
}
188188

189-
// Invoked when a notification arrived while the app was running in the foreground.
189+
// Invoked when a notification arrives while the app was running in the foreground.
190190
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
191191
willPresentNotification:(UNNotification *)notification
192192
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
@@ -217,7 +217,7 @@ On the [Azure Portal](https://portal.azure.com) page for your notification hub,
217217

218218
![Get Connection String](img/GetConnectionString.png)
219219

220-
The example below shows how you can register and unregister from Azure Notification Hub in your React component.
220+
The example below shows how you can register and unregister from Azure Notification Hub in your React Native component.
221221

222222
```js
223223
import React, { Component } from 'react';
@@ -233,7 +233,7 @@ const NotificationHub = require('react-native-azurenotificationhub/index.ios');
233233

234234
const connectionString = '...'; // The Notification Hub connection string
235235
const hubName = '...'; // The Notification Hub name
236-
const tags = [ '...' ]; // The set of tags to subscribe to
236+
const tags = [ '...' ]; // The set of tags to subscribe to. See notes after code sample
237237
const template = '...'; // Notification hub templates:
238238
// https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-templates-cross-platform-push-messages
239239
const templateName = '...'; // The template's name
@@ -281,32 +281,32 @@ export default class App extends Component {
281281
// resolves to the current state of the permission of
282282
// {alert: boolean, badge: boolean,sound: boolean }
283283
NotificationHub.requestPermissions()
284-
.then((res) => console.warn(res))
285-
.catch(reason => console.warn(reason));
284+
.then(console.log)
285+
.catch(console.warn);
286286
}
287287

288288
register() {
289289
NotificationHub.register(remoteNotificationsDeviceToken, { connectionString, hubName, tags })
290-
.then((res) => console.warn(res))
291-
.catch(reason => console.warn(reason));
290+
.then(console.log)
291+
.catch(console.warn);
292292
}
293293

294294
registerTemplate() {
295295
NotificationHub.registerTemplate(remoteNotificationsDeviceToken, { connectionString, hubName, tags, templateName, template })
296-
.then((res) => console.warn(res))
297-
.catch(reason => console.warn(reason));
296+
.then(console.log)
297+
.catch(console.warn);
298298
}
299299

300300
unregister() {
301301
NotificationHub.unregister()
302-
.then((res) => console.warn(res))
303-
.catch(reason => console.warn(reason));
302+
.then(console.log)
303+
.catch(console.warn);
304304
}
305305

306306
unregisterTemplate() {
307307
NotificationHub.unregisterTemplate(templateName)
308-
.then((res) => console.warn(res))
309-
.catch(reason => console.warn(reason));
308+
.then(console.log)
309+
.catch(console.warn);
310310
}
311311

312312
render() {
@@ -420,32 +420,38 @@ export default class App extends Component {
420420
}
421421

422422
const styles = StyleSheet.create({
423-
container: {
424-
flex: 1,
425-
justifyContent: 'center',
426-
alignItems: 'center',
427-
backgroundColor: '#F5FCFF',
428-
},
429-
welcome: {
430-
fontSize: 20,
431-
textAlign: 'center',
432-
margin: 10,
433-
},
434-
instructions: {
435-
textAlign: 'center',
436-
color: '#333333',
437-
marginBottom: 5,
438-
},
439-
button: {
440-
backgroundColor: '#295a7b',
441-
borderRadius: 4,
442-
justifyContent: 'center',
443-
alignItems: 'center',
444-
margin: 14,
445-
},
446-
buttonText: {
447-
color: '#333333',
448-
},
423+
container: {
424+
flex: 1,
425+
justifyContent: 'center',
426+
alignItems: 'center',
427+
backgroundColor: '#FFF',
428+
},
429+
welcome: {
430+
fontSize: 20,
431+
textAlign: 'center',
432+
margin: 10,
433+
},
434+
instructions: {
435+
textAlign: 'center',
436+
color: '#FFF',
437+
marginBottom: 5,
438+
},
439+
button: {
440+
backgroundColor: '#0071c9',
441+
borderRadius: 4,
442+
justifyContent: 'center',
443+
alignItems: 'center',
444+
padding: 14,
445+
marginVertical: 14,
446+
},
447+
buttonText: {
448+
color: '#FFF',
449+
},
449450
});
450-
451451
```
452+
453+
## A Note On Tags
454+
455+
Azure Notification Hubs uses "tags" to target notifications. To receive targeted notifications, a device subscribes to those tags when registering (they are sent in an array by the `register` and `registerTemplate` methods above). So, if you want to send a notification to one device, that device must register on a unique tag, and report that tag to your backend, where it can be associated with your user. This is a contrast to other notification platforms, which often give you a unique ID during the registration process for this purpose.
456+
457+
Needing to supply your own unique, non-random string (you'll want it again when you unregister the device in your backend) could lead to the temptation to use the device's unique identifier (device ID/UDID) to register for notifications. [There are numerous privacy and security reasons not to do this](https://books.nowsecure.com/secure-mobile-development/en/sensitive-data/limit-use-of-uuid.html).

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare namespace AzureNotificationHub {
33
connectionString: string;
44
hubName: string;
55
senderID: string;
6-
tags?: string[];
6+
tags: string[];
77
channelName: string;
88
channelImportance: boolean;
99
channelShowBadge: boolean;

0 commit comments

Comments
 (0)