@@ -9,7 +9,7 @@ react-native init ReactNativeAzureNotificationHubSample
9
9
```
10
10
11
11
In addition to the standard React Native requirements, you will also need the following:
12
- * An iOS 9 (or later version)-capable device (simulator doesn't work with push notifications)
12
+ * An iOS 10 (or later version)-capable device (simulator doesn't work with push notifications)
13
13
* [ Apple Developer Program] ( https://developer.apple.com/programs/ ) membership
14
14
15
15
## Install react-native-azurenotificationhub
@@ -156,34 +156,44 @@ Add the following line to your `ios/Podfile` file and run **pod install**
156
156
* And then add the following code in the same file:
157
157
158
158
``` objective-c
159
- // Required to register for notifications
160
- - (void )application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
159
+ - (BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
161
160
{
162
- [RCTAzureNotificationHubManager didRegisterUserNotificationSettings:notificationSettings];
161
+ ...
162
+
163
+ // Registering for local notifications
164
+ [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
165
+
166
+ return YES;
163
167
}
164
168
165
- // Required for the register event .
169
+ // Invoked when the app successfully registered with Apple Push Notification service (APNs) .
166
170
- (void )application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
167
171
{
168
172
[RCTAzureNotificationHubManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
169
173
}
170
174
171
- // Required for the registrationError event .
175
+ // Invoked when APNs cannot successfully complete the registration process .
172
176
- (void )application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
173
177
{
174
178
[RCTAzureNotificationHubManager didFailToRegisterForRemoteNotificationsWithError:error];
175
179
}
176
180
177
- // Required for the notification event.
178
- - (void )application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
181
+ // Invoked when a remote notification arrived and there is data to be fetched.
182
+ - (void )application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
183
+ fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
179
184
{
180
- [RCTAzureNotificationHubManager didReceiveRemoteNotification:notification];
185
+ [RCTAzureNotificationHubManager didReceiveRemoteNotification:userInfo
186
+ fetchCompletionHandler:completionHandler];
181
187
}
182
188
183
- // Required for the localNotification event.
184
- - (void )application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
189
+ // Invoked when a notification arrived while the app was running in the foreground.
190
+ - (void )userNotificationCenter:(UNUserNotificationCenter *)center
191
+ willPresentNotification:(UNNotification *)notification
192
+ withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
185
193
{
186
- [RCTAzureNotificationHubManager didReceiveLocalNotification:notification];
194
+ [RCTAzureNotificationHubManager userNotificationCenter:center
195
+ willPresentNotification:notification
196
+ withCompletionHandler:completionHandler];
187
197
}
188
198
```
189
199
@@ -221,9 +231,12 @@ import {
221
231
222
232
const NotificationHub = require (' react-native-azurenotificationhub/index.ios' );
223
233
224
- const connectionString = ' ...' ; // The Notification Hub connection string
225
- const hubName = ' ...' ; // The Notification Hub name
226
- const tags = [ ... ]; // The set of tags to subscribe to
234
+ const connectionString = ' ...' ; // The Notification Hub connection string
235
+ const hubName = ' ...' ; // The Notification Hub name
236
+ const tags = [ ... ]; // The set of tags to subscribe to
237
+ const template = ' ...' ; // Notification hub templates:
238
+ // https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-templates-cross-platform-push-messages
239
+ const templateName = ' ...' ; // The template's name
227
240
228
241
let remoteNotificationsDeviceToken = ' ' ; // The device token registered with APNS
229
242
@@ -267,15 +280,33 @@ export default class App extends Component {
267
280
// rejects, or if the permissions were previously rejected. The promise
268
281
// resolves to the current state of the permission of
269
282
// {alert: boolean, badge: boolean,sound: boolean }
270
- NotificationHub .requestPermissions ();
283
+ NotificationHub .requestPermissions ()
284
+ .then ((res ) => console .warn (res))
285
+ .catch (reason => console .warn (reason));
271
286
}
272
287
273
288
register () {
274
- NotificationHub .register (remoteNotificationsDeviceToken, {connectionString, hubName, tags});
289
+ NotificationHub .register (remoteNotificationsDeviceToken, { connectionString, hubName, tags })
290
+ .then ((res ) => console .warn (res))
291
+ .catch (reason => console .warn (reason));
292
+ }
293
+
294
+ registerTemplate () {
295
+ NotificationHub .registerTemplate (remoteNotificationsDeviceToken, { connectionString, hubName, tags, templateName, template })
296
+ .then ((res ) => console .warn (res))
297
+ .catch (reason => console .warn (reason));
275
298
}
276
299
277
300
unregister () {
278
- NotificationHub .unregister ();
301
+ NotificationHub .unregister ()
302
+ .then ((res ) => console .warn (res))
303
+ .catch (reason => console .warn (reason));
304
+ }
305
+
306
+ unregisterTemplate () {
307
+ NotificationHub .unregisterTemplate (templateName)
308
+ .then ((res ) => console .warn (res))
309
+ .catch (reason => console .warn (reason));
279
310
}
280
311
281
312
render () {
@@ -295,13 +326,27 @@ export default class App extends Component {
295
326
< / Text >
296
327
< / View>
297
328
< / TouchableOpacity>
329
+ < TouchableOpacity onPress= {this .registerTemplate .bind (this )}>
330
+ < View style= {styles .button }>
331
+ < Text style= {styles .buttonText }>
332
+ Register Template
333
+ < / Text >
334
+ < / View>
335
+ < / TouchableOpacity>
298
336
< TouchableOpacity onPress= {this .unregister .bind (this )}>
299
337
< View style= {styles .button }>
300
338
< Text style= {styles .buttonText }>
301
339
Unregister
302
340
< / Text >
303
341
< / View>
304
342
< / TouchableOpacity>
343
+ < TouchableOpacity onPress= {this .unregisterTemplate .bind (this )}>
344
+ < View style= {styles .button }>
345
+ < Text style= {styles .buttonText }>
346
+ Unregister Template
347
+ < / Text >
348
+ < / View>
349
+ < / TouchableOpacity>
305
350
< / View>
306
351
);
307
352
}
0 commit comments