npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-mo-pushnotification

v0.1.25

Published

react-native pushnotification push notifications for ios and android

Downloads

12

Readme

react-native-mo-pushnotification

Push Notifications

Installation

Install just like your ordinary react-native module.

For iOS:

  • Enable Push Notification capability

For Android:

  • Add Firebase (google-services.json)
  • apply plugin: 'com.google.gms.google-services' in app/build.gradle

TODO

  • show local notifications
    • extra page?
  • send notification
    • extra page?
  • initial interaction?
  • ios firebase token?

Usage

Please check the example/ code.

import { PushNotification } from 'react-native-mo-pushnotification';

// for debugging:
PushNotification.setVerbose(true);

Permissions

// ask for permissions
if (await PushNotification.getPermissionStatus() !== PushNotificationPermissionStatus.GRANTED) {
  await PushNotification.requestPermission();
}

// open settings
await PushNotification.openSettings();

Push Token

const token = await PushNotification.requestToken();
console.log('type', token.type); // ios-dev, ios or android-fcm.
// if this is ios-dev you need to send the push via apn-sandbox
console.log('token', token.token);
console.log('locale', token.locale); // en-US
console.log('id', token.id); // android app id or ios bundle id

Show Notification

const notificationID = await PushNotification.showNotification({
  title: 'title',
  body: 'body',
  subtitle: 'subtitle',
  data: { someContextData: 'test' },
  badge: 2,
  ongoing: true,
  android: {
    // additional android args
    smallIcon: 'ic_icon_resource',
    channelID: 'my_channel',
    actions: [
      { id: 'id1', title: 'some-action-button' },
      { id: 'id1', html: '<font color="red">some-other-button</font>', background: true },
      // background will prevent the activity from being launched
    ],
  },
  ios: {
    // additional ios args
    categoryIdentifier: 'category1',
  },
});

Interaction

const subscription = PushNotification.onNotification.subscribe((notification) => {
  // handle incoming data notification
});
// later:
subscription.release();

PushNotification.onInteraction.subscribe((notification) => {
  console.log('notification clicked!', notification);
  console.log('action', notification.action);
  // if you have added buttons to the notification, action will tell you
  // which one was pressed.
});

PushNotification.onShowNotification = (notification) => {
  if (currentPage === 'chat' && isChatNotification(notification)) {
    // do not show the notification
    tellChatPageToRefresh();
    return false;
  } else {
    return true;
  }
};

Existing notifications

// get existing notifications
const notifications = await PushNotification.getNotifications();
for (const notification of notifications) {
  // and remove them
  await PushNotification.removeNotification(notification.id);
}

Misc

// run with background task / wake lock
await PushNotification.runInBackground(async () => {
  // handle something that should not be interrupted
});

iOS

// set application badge
await PushNotification.iosSetBadge(99);

// setup categories
await PushNotification.iosSetupCategories([
  {
    identifier: 'category1',
    options: IosCategoryOptions.AllowInCarPlay + IosCategoryOptions.CustomDismissAction,
    intentIdentifiers: [],
    actions: [
      { identifier: 'action1', title: 'start-app', options: IosCategoryActionOptions.Foreground },
      // foreground will make this launch the app
      { identifier: 'cation2', title: 'cancel', options: IosCategoryActionOptions.Destructive },
    ],
  },
]);

Android

// setup channels
await PushNotification.androidSetupChannels([
  {
    id: 'channel1',
    name: 'Channel 1',
    lockscreenVisibility: ...,
    bypassDnd: true,
    sound: 'sound_resource_raw',
  },
]);

// start main activity. very limited since android Q
await PushNotification.androidStartMainActivity();