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

notification react native

yarn add react-native-push-notification
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 :: p5js no stroke 
Javascript :: lodash omitby 
Javascript :: modal example react native 
Javascript :: jstree expend all node 
Javascript :: javascript break inner loop 
Javascript :: pass object in asyncstorage in react native 
Javascript :: js addeventlistener keyup android 
Javascript :: SHOPIFY COUNTRY SELECTOR 
Javascript :: javascript online compiler 
Javascript :: res.write in node js 
Javascript :: uncaught type error event listener error 
Javascript :: fs renameSync 
Javascript :: using sequelize to read from a table 
Javascript :: express alternatives 
Javascript :: mongoose connections 
Javascript :: js recursive fetch 
Javascript :: if javascript 
Javascript :: Google App Script getSheetByName 
Javascript :: mongoose get elements that contain substring 
Javascript :: textinput onpress react native 
Javascript :: You are trying to create a styled element with an undefined component.You may have forgotten to import it. 
Javascript :: react native refresh on pull down 
Javascript :: escape xss javascript 
Javascript :: js text match 
Javascript :: example of call by value and call by reference in javascript 
Javascript :: google places autocomplete react native 
Javascript :: window width onload jquery 
Javascript :: puppeteer click element with custom property 
Javascript :: read files in javascript 
Javascript :: node js code for saving first middle and last name 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =