Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

push notification react native

/**
 * @format
 */

import PushNotificationIOS from '@react-native-community/push-notification-ios';
import { AppRegistry } from 'react-native';
import PushNotification from 'react-native-push-notification';
import App from './App';
import { name as appName } from './app.json';

// Must be outside of any component LifeCycle (such as `componentDidMount`).
PushNotification.configure({
  // (optional) Called when Token is generated (iOS and Android)
  onRegister: function (token) {
    console.log('TOKEN:', token);
  },

  // (required) Called when a remote is received or opened, or local notification is opened
  onNotification: function (notification) {
    console.log('NOTIFICATION:', notification);

    // process the notification
    // (required) Called when a remote is received or opened, or local notification is opened
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  },

  // (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
  onAction: function (notification) {
    console.log('ACTION:', notification.action);
    console.log('NOTIFICATION:', notification);
    // process the action
  },

  // (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
  onRegistrationError: function (err) {
    console.error(err.message, err);
  },

  // IOS ONLY (optional): default: all - Permissions to register.
  permissions: {
    alert: true,
    badge: true,
    sound: true,
  },

  // Should the initial notification be popped automatically
  // default: true

  popInitialNotification: true,

  /**
   * (optional) default: true
   * - Specified if permissions (ios) and token (android and ios) will requested or not,
   * - if not, you must call PushNotificationsHandler.requestPermissions() later
   * - if you are not using remote notification or do not have Firebase installed, use this:
   *     requestPermissions: Platform.OS === 'ios'
   */

  requestPermissions: true,
});

AppRegistry.registerComponent(appName, () => App);
Comment

react native push notifications npm

import PushNotificationIOS from '@react-native-community/push-notification-ios';
Comment

react native push notifications npm

export const App = () => {
  const [permissions, setPermissions] = useState({});

  useEffect(() => {
    PushNotificationIOS.addEventListener('notification', onRemoteNotification);
  });

  const onRemoteNotification = (notification) => {
    const isClicked = notification.getData().userInteraction === 1;

    if (isClicked) {
      // Navigate user to another screen
    } else {notificat
      // Do something else with push ion
    }
  };
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to download json object that come from backend in react 
Javascript :: mvc asp.net partial view from js 
Javascript :: firebase realtime database increment value 
Javascript :: copy folder in nodejs 
Javascript :: adding pre tag javascript 
Javascript :: jsoup 
Javascript :: javascript how to select a array 
Javascript :: for loop in react native 
Javascript :: autofocus is not working in react native 
Javascript :: working of a recursive function 
Javascript :: scrollbar position 
Javascript :: data table buttons 
Javascript :: destroy method 
Javascript :: what is lodash omitBy 
Javascript :: button is not calling js function 
Javascript :: what is the meaning of the table innerhtml in javascript 
Javascript :: discord.js command cooldown 
Javascript :: react validate 
Javascript :: update TextInput value react-hook-form react-admin 
Javascript :: fastify query 
Javascript :: javascript replace class tailwindcss 
Javascript :: JavaScript Change the Elements of an Array 
Javascript :: images node backend server 
Javascript :: js Changing selected option by option text 
Javascript :: javascript round big numbers 
Javascript :: (function (g, d, a) {})(window, document, jQuery); 
Javascript :: Prism synchronizationContext 
Python :: discord bot status python 
Python :: python - show all columns / rows of a Pandas Dataframe 
Python :: how to make a letter animation in python 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =