@@ -9,7 +9,7 @@ react-native init ReactNativeAzureNotificationHubSample
99```
1010
1111In 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)
1313* [ Apple Developer Program] ( https://developer.apple.com/programs/ ) membership
1414
1515## Install react-native-azurenotificationhub
@@ -156,34 +156,44 @@ Add the following line to your `ios/Podfile` file and run **pod install**
156156* And then add the following code in the same file:
157157
158158``` objective-c
159- // Required to register for notifications
160- - (void )application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
159+ - (BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
161160{
162- [RCTAzureNotificationHubManager didRegisterUserNotificationSettings:notificationSettings];
161+ ...
162+
163+ // Registering for local notifications
164+ [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
165+
166+ return YES;
163167}
164168
165- // Required for the register event .
169+ // Invoked when the app successfully registered with Apple Push Notification service (APNs) .
166170- (void )application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
167171{
168172 [RCTAzureNotificationHubManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
169173}
170174
171- // Required for the registrationError event .
175+ // Invoked when APNs cannot successfully complete the registration process .
172176- (void )application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
173177{
174178 [RCTAzureNotificationHubManager didFailToRegisterForRemoteNotificationsWithError:error];
175179}
176180
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
179184{
180- [RCTAzureNotificationHubManager didReceiveRemoteNotification:notification];
185+ [RCTAzureNotificationHubManager didReceiveRemoteNotification:userInfo
186+ fetchCompletionHandler:completionHandler];
181187}
182188
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
185193{
186- [RCTAzureNotificationHubManager didReceiveLocalNotification:notification];
194+ [RCTAzureNotificationHubManager userNotificationCenter:center
195+ willPresentNotification:notification
196+ withCompletionHandler:completionHandler];
187197}
188198```
189199
@@ -221,9 +231,12 @@ import {
221231
222232const NotificationHub = require (' react-native-azurenotificationhub/index.ios' );
223233
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
227240
228241let remoteNotificationsDeviceToken = ' ' ; // The device token registered with APNS
229242
@@ -267,15 +280,33 @@ export default class App extends Component {
267280 // rejects, or if the permissions were previously rejected. The promise
268281 // resolves to the current state of the permission of
269282 // {alert: boolean, badge: boolean,sound: boolean }
270- NotificationHub .requestPermissions ();
283+ NotificationHub .requestPermissions ()
284+ .then ((res ) => console .warn (res))
285+ .catch (reason => console .warn (reason));
271286 }
272287
273288 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));
275298 }
276299
277300 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));
279310 }
280311
281312 render () {
@@ -295,13 +326,27 @@ export default class App extends Component {
295326 < / Text >
296327 < / View>
297328 < / 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>
298336 < TouchableOpacity onPress= {this .unregister .bind (this )}>
299337 < View style= {styles .button }>
300338 < Text style= {styles .buttonText }>
301339 Unregister
302340 < / Text >
303341 < / View>
304342 < / 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>
305350 < / View>
306351 );
307352 }
0 commit comments