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-easy-push-notifications

v3.0.2

Published

[![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger) ![Supports Android and iOS](https://img.shields.io/badge/platforms-android%20|%20ios-lightgrey.svg?style=flat-square) [![License](htt

Downloads

46

Readme

react-native-easy-push-notifications

Build Status Supports Android and iOS License NPM Version

React-Native-Easy-Push-Notifications is developed to help the react-native developers in speeding-up their development process. This package leverages the developer from implementing notifications easily. The implementation is kept point-to-point to provide easy usage to the developer. Follow the guide below to get you up and running with the notifications:

Installation

If you prefer npm,

$ npm install react-native-easy-push-notifications --save

If you prefer yarn,

$ yarn add react-native-easy-push-notifications

Setup FireBase Project

  • Go to firebase console https://firebase.google.com/
  • Log-in to your google account and add a project with any name you like.
  • After successfull creation of the project you will be shown homepage of your project.

Android

Android setup is a two step process. The first step can be done in two ways:

First Step:

Way 1:
  • Go to settings -> Project Settings -> scroll to bottom and add an android application.
  • Add android package name. ( You can find package name in your Manifest.xml )
  • Click on the Register button.
  • Download the google-services.json and place it in the android -> app .
  • Click on the Next button and go to your Project level build.gradle.
  • Inside your /build.gradle:
    • Add firebase_messaging = '20.1.0' to buildscript -> ext.
    • Add google() // Google's Maven repository to buildscript -> repositories.
    • Add classpath 'com.google.gms:google-services:4.3.3' to buildscript -> dependencies.
    • Add google() // Google's Maven repository to allprojects -> repositories.
  • Go to App level build.gradle and add following lines:
    • Add apply plugin: 'com.google.gms.google-services' after apply plugin: "com.android.application" .
    • Add implementation 'com.google.firebase:firebase-messaging:20.1.0' to dependencies.
    • Click on the Next button and then continue to the console.
Way 2:
  • Open project in Android studio.
  • login to your google account.
  • Go to Tools -> Firebase -> Cloud Messaging -> Setup Firebase Cloud Messaging from Android studio options.
  • Click on Connect To Firebase button and from existing FireBase project dropdown, select the project we created in setup firebase section. Click on connect
  • Click on Add FCM to your app button and then click on Accept changes button shown in the dialog.
  • In your Project level build.gradle, Add firebase_messaging = '20.1.0' to buildscript -> ext.

Second Step:

  • Open Manifest.xml and following line of code to it:
    • Add android:launchMode="singleTop" to Activity tag with name: .MainActivity.
    • Add following service tag to Manifest.xml:
    <service android:name="com.blitzapp.module.push.NotificationsService"
              android:exported="false">
      <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
    </service>
    • Add following meta-data tag to Manifest.xml:
    <meta-data android:name="com.google.firebase.messaging.default_notification_icon"
               android:resource="@drawable/notifications_icon" />
  • notifications_icon is required. You can generate this icon from here: Icon generate link
  • Place the icon generated in the drawable folder.
  • Go to the MainActivity.java and add following lines of code:
    • Add this to imports: import com.blitzapp.module.push.RNEasyPushNotificationsModule;
    • Add this function :
    @Override
    public void onNewIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            for (String key : extras.keySet()) {
                Object value = extras.get(key);
                Log.d("MainActivity", "Extras received at onNewIntent:  Key: " + key + " Value: " + value);
            }
    
            String title = extras.getString("title");
            String message = extras.getString("body");
            if (message != null && message.length() > 0) {
                RNEasyPushNotificationsModule.setExtras(extras);
            }
            JSONObject json = new JSONObject();
            Set<String> keys = extras.keySet();
            for (String key : keys) {
                try {
                    json.put(key, JSONObject.wrap(extras.get(key)));
                } catch(JSONException e) {
                    //Handle exception here
                }
            }
            String data = "";
            try {
                data = json.getString("data");
    
            } catch (JSONException e) {
                e.printStackTrace();
                data = json.toString();
            }
            Intent i = new Intent("onNotificationTap");
    
            i.putExtra("data", data);
            LocalBroadcastManager.getInstance(this).sendBroadcast(i);
        }
    }
    - Add this segment to onCreate method:
    ```sh
    if(RNEasyPushNotificationsModule.activityToOpen == null){
      RNEasyPushNotificationsModule.activityToOpen = this;
    }
    
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    if (extras != null) {
      for (String key : extras.keySet()) {
        Object value = extras.get(key);
        Log.d("MainActivity", "Extras received at onCreate:  Key: " + key + " Value: " + value);
      }
    
      String title = extras.getString("title");
      String message = extras.getString("body");
      if (message != null && message.length() > 0) {
        RNEasyPushNotificationsModule.setExtras(extras);
      }
    }

ios

IOS setup is a two step process.

First Step:

  • Go to settings -> Project Settings -> scroll to bottom and add an ios applicaton.
  • Add your ios app bundle identifer and click on the Next button.
  • Download the GoogleService-Info.plist and drag it into your project in Xcode.
  • Click on the Next, then Next and then Continue to the console.

Second Step:

  • Go to developer.apple.com and then go to certificates,Ids and profiles -> identifiers -> your app identifier -> Push Notifications and enable it.
  • Open your project in Xcode and go to Signing & capabilities -> Capability -> enable Push Notifications.
  • Open your podfile and Add pod 'RNEasyPushNotificationsModule', :path => '../node_modules/react-native-easy-push-notifications'.
  • Open terminal at root of your project and run following commands:
$ cd ios
$ pod install
  • Add #import "RNEasyPushNotificationsModule.h" to the imports section.
  • Open your app's Appdelegate.h and add the following code to the interface section:
{
RNEasyPushNotificationsModule *nModule;
NSDictionary *dic;
}
-(NSDictionary *)getLaunchOptions;
+(RCTBridge *) getSharedBridge;
  • Open your app's Appdelegate.m and add the following code to the didFinishLaunchingWithOptions method:
if (launchOptions!=nil) {
NSMutableDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSLog(@"userInfo===%@", userInfo);
if (userInfo.count>=1) {
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
NSLog(@"Received apsInfo Badge: %@", userInfo);
RNEasyPushNotificationsModule *nModule = [RNEasyPushNotificationsModule allocWithZone: nil];
[nModule setRemoteNotification:userInfo];
  }
}

React Native

After setting up our project on both android and ios, we are all set to consume this module in react native. Following are the usage of functions exposed by this package:

import reactNativeEasyPushNotifications from 'react-native-easy-push-notifications';

componentDidMount(){
    reactNativeEasyPushNotifications.getDeviceId( deviceId => {
            console.log("My device id ", deviceId);
        // This method gives the device id which is returned by the firebase
        })
       
    reactNativeEasyPushNotifications.onMessageReceived(notif => {
            console.log("onMessageReceived:", notif);
        // This method is triggered whenever the app is in foreground and we receive the notification
        })
       
    reactNativeEasyPushNotifications.getLastNotificationData(notif => {
            console.log("getLastNotificationData:", notif);
        // This method is triggered whenever the user taps on the notification
        })
}

Todos

We aim to make this package even more robust and powerful by adding following features in the upcoming releases:

  • Reply from notification
  • Add support to view image in notification
  • Add an example project
  • Notification testing dashboard

License

MIT