diff --git a/releases/next/docs/pushnotificationios.html b/releases/next/docs/pushnotificationios.html index 91afa1e57c1..f165307fbbb 100644 --- a/releases/next/docs/pushnotificationios.html +++ b/releases/next/docs/pushnotificationios.html @@ -11,6 +11,11 @@ and your server-side system. To get an idea, { [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } + // Required for the registrationError event. + - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error + { + [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; + } // Required for the notification event. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification { @@ -20,17 +25,16 @@ and your server-side system. To get an idea, - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [RCTPushNotificationManager didReceiveLocalNotification:notification]; - } - - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error - { - NSLog(@"%@", error); }

Methods #

static presentLocalNotification(details) #

Schedules the localNotification for immediate presentation.

details is an object containing:

  • alertBody : The message displayed in the notification alert.
  • alertAction : The "action" displayed beneath an actionable notification. Defaults to "view";
  • soundName : The sound played when the notification is fired (optional).
  • category : The category of this notification, required for actionable notifications (optional).
  • userInfo : An optional object containing additional notification data.
  • applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. The default value of this property is 0, which means that no badge is displayed.

static scheduleLocalNotification(details) #

Schedules the localNotification for future presentation.

details is an object containing:

  • fireDate : The date and time when the system should deliver the notification.
  • alertBody : The message displayed in the notification alert.
  • alertAction : The "action" displayed beneath an actionable notification. Defaults to "view";
  • soundName : The sound played when the notification is fired (optional).
  • category : The category of this notification, required for actionable notifications (optional).
  • userInfo : An optional object containing additional notification data.
  • applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. Setting the number to 0 removes the icon badge.

static cancelAllLocalNotifications(0) #

Cancels all scheduled localNotifications

static setApplicationIconBadgeNumber(number) #

Sets the badge number for the app icon on the home screen

static getApplicationIconBadgeNumber(callback) #

Gets the current badge number for the app icon on the home screen

static cancelLocalNotifications(userInfo) #

Cancel local notifications.

Optionally restricts the set of canceled notifications to those notifications whose userInfo fields match the corresponding fields in the userInfo argument.

static getScheduledLocalNotifications(callback) #

Gets the local notifications that are currently scheduled.

static addEventListener(type, handler) #

Attaches a listener to remote or local notification events while the app is running in the foreground or the background.

Valid events are:

  • notification : Fired when a remote notification is received. The handler will be invoked with an instance of PushNotificationIOS.
  • localNotification : Fired when a local notification is received. The handler will be invoked with an instance of PushNotificationIOS.
  • register: Fired when the user registers for remote notifications. The -handler will be invoked with a hex string representing the deviceToken.

static removeEventListener(type, handler) #

Removes the event listener. Do this in componentWillUnmount to prevent +handler will be invoked with a hex string representing the deviceToken.

  • registrationError: Fired when the user fails to register for remote +notifications. Typically occurs when APNS is having issues, or the device +is a simulator. The handler will be invoked with +{message: string, code: number, details: any}.
  • static removeEventListener(type, handler) #

    Removes the event listener. Do this in componentWillUnmount to prevent memory leaks

    static requestPermissions(permissions?) #

    Requests notification permissions from iOS, prompting the user's dialog box. By default, it will request all notification permissions, but a subset of these can be requested by passing a map of requested @@ -75,17 +79,19 @@ class Button extends NotificationExample extends React.Component { componentWillMount() { - // Add listener for push notifications - PushNotificationIOS.addEventListener('notification', this._onNotification); - // Add listener for local notifications - PushNotificationIOS.addEventListener('localNotification', this._onLocalNotification); + PushNotificationIOS.addEventListener('register', this._onRegistered); + PushNotificationIOS.addEventListener('registrationError', this._onRegistrationError); + PushNotificationIOS.addEventListener('notification', this._onRemoteNotification); + PushNotificationIOS.addEventListener('localNotification', this._onLocalNotification); + + PushNotificationIOS.requestPermissions(); } componentWillUnmount() { - // Remove listener for push notifications - PushNotificationIOS.removeEventListener('notification', this._onNotification); - // Remove listener for local notifications - PushNotificationIOS.removeEventListener('localNotification', this._onLocalNotification); + PushNotificationIOS.removeEventListener('register', this._onRegistered); + PushNotificationIOS.removeEventListener('registrationError', this._onRegistrationError); + PushNotificationIOS.removeEventListener('notification', this._onRemoteNotification); + PushNotificationIOS.removeEventListener('localNotification', this._onLocalNotification); } render() { @@ -126,7 +132,29 @@ class NotificationExample extends }); } - _onNotification(notification) { + _onRegistered(deviceToken) { + AlertIOS.alert( + 'Registered For Remote Push', + `Device Token: ${deviceToken}`, + [{ + text: 'Dismiss', + onPress: null, + }] + ); + } + + _onRegistrationError(error) { + AlertIOS.alert( + 'Failed To Register For Remote Push', + `Error (${error.code}): ${error.message}`, + [{ + text: 'Dismiss', + onPress: null, + }] + ); + } + + _onRemoteNotification(notification) { AlertIOS.alert( 'Push Notification Received', 'Alert message: ' + notification.getMessage(), @@ -195,8 +223,6 @@ exports.examples { title: 'Badge Number', render(): ReactElement<any> { - PushNotificationIOS.requestPermissions(); - return ( <View> <Button