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 🙏

© 2026 – Pkg Stats / Ryan Hefner

appambit-push-notifications

v1.1.0

Published

Push Notifications SDK for Android to send push notifications via AppAmbit platform.

Readme

AppAmbit Push Notifications SDK

Seamlessly integrate push notifications with your AppAmbit analytics.

This SDK is an extension of the core AppAmbit SDK, providing a simple and powerful way to handle Firebase Cloud Messaging (FCM) notifications on both Android and iOS.


Contents


Features

  • Zero-Config iOS: No AppDelegate changes required — the SDK wires itself up automatically via method swizzling.
  • Simple Setup: Integrates in minutes.
  • Enable/Disable Notifications: Easily manage user preferences at both the business and FCM level.
  • Robust Event Listeners: Separate callbacks for Foreground and Opened (tapped) notifications on both platforms, Background listener is Android-only.
  • Android Headless JS Support: Handle background notifications via React Native Headless JS tasks even when the app is completely closed.
  • Automatic Field Handling: Automatically uses standard FCM payload fields like color, icon, channel_id, click_action, and rich images.
  • Rich Media Support: Full iOS Notification Service Extension support for rich payloads, badges, and media attachments.
  • Permission Helpers: Utilities to request and check the POST_NOTIFICATIONS permission.

Requirements

  • AppAmbit Core SDK: Requires the core appambit SDK to be installed and configured.
  • Firebase Project: A configured Firebase project with google-services.json (Android) and GoogleService-Info.plist (iOS) in your application.
  • OS Versions: Android API level 21 (Lollipop) or newer / iOS 13.0 or newer.

Install

npm install appambit
npm install appambit-push-notifications

Android Dependencies

Add the following to your Gradle files. Your app is responsible for providing the Firebase BOM and Firebase Messaging to ensure version compatibility.

android/app/build.gradle (Groovy)

apply plugin: "com.google.gms.google-services"

dependencies {
    implementation platform('com.google.firebase:firebase-bom:33.1.2')
    implementation 'com.google.firebase:firebase-messaging:23.4.0'
}

android/build.gradle (Groovy)

dependencies {
    classpath("com.google.gms:google-services:4.3.15")
}

android/app/build.gradle.kts

apply(plugin = "com.google.gms.google-services")

dependencies {
    implementation(platform("com.google.firebase:firebase-bom:33.1.2"))
    implementation("com.google.firebase:firebase-messaging:23.4.0")
}

android/build.gradle.kts

dependencies {
    classpath("com.google.gms:google-services:4.3.15")
}

iOS Dependencies

After installing the npm package, run:

cd ios && pod install

Quickstart

In your App.tsx (or application entry point), initialize both SDKs in order:

import * as AppAmbit from "appambit";
import * as PushNotifications from "appambit-push-notifications";

AppAmbit.start("<YOUR-APPKEY>");
PushNotifications.start();
PushNotifications.requestNotificationPermission();

Usage

Event Listeners

All listeners hold a single subscription — calling them again silently replaces the previous one. Each returns a cleanup function to call on unmount (e.g. in useEffect's return).

Foreground Listener

Fires when a notification arrives while the app is active and open.

useEffect(() => {
  const unsubscribe = PushNotifications.setForegroundListener((payload) => {
    console.log("Foreground notification:", payload);
  });
  return () => unsubscribe();
}, []);

Background Listener

Fires when a notification arrives while the app is backgrounded or (on Android) killed.

Android only: To handle notifications when the app is completely killed, you must also register a Headless JS task — see Android Setup.

useEffect(() => {
  const unsubscribe = PushNotifications.Android.setBackgroundListener(async (payload) => {
    console.log("Background notification:", payload);
    // The SDK automatically signals the OS when your Promise resolves
  });
  return () => unsubscribe();
}, []);

Opened Listener

Fires when the user taps a notification. Works regardless of whether the app was in the foreground, background, or killed.

useEffect(() => {
  const unsubscribe = PushNotifications.setOpenedListener((payload) => {
    console.log("Notification tapped:", payload);
  });
  return () => unsubscribe();
}, []);

Notification Payload

interface NotificationPayload {
  title: string | null;
  body: string | null;
  imageUrl: string | null;
  data: Record<string, string>;
  android: {
    color: string | null;
    smallIconName: string | null;
    ticker: string | null;
    sticky: boolean | null;
    visibility: string | null;
    channelId: string | null;
    tag: string | null;
    sound: string | null;
    clickAction: string | null;
  } | null;
  ios: {
    badge: number | null;
    sound: string | null;
    category: string | null;
    threadId: string | null;
  } | null;
}

Permission Helpers

// Fire-and-forget — shows the system permission dialog
PushNotifications.requestNotificationPermission();

// Returns Promise<boolean> with the user's decision
const granted = await PushNotifications.requestNotificationPermissionWithResult();

// Check current permission status without prompting the user
const hasPermission = await PushNotifications.hasNotificationPermission();

Enable / Disable Notifications

PushNotifications.setNotificationsEnabled(false);  // opt out
PushNotifications.setNotificationsEnabled(true);   // opt back in

const isEnabled = await PushNotifications.isNotificationsEnabled();

Native Implementation Setup

Android Setup

The SDK's AndroidManifest.xml automatically merges the required permissions (POST_NOTIFICATIONS, RECEIVE_BOOT_COMPLETED), AppAmbitInitProvider, and AppAmbitHeadlessService into your app — no manifest changes needed.

To handle notifications when the app is completely killed, register a Headless JS task in your index.js:

import { AppRegistry, Platform } from 'react-native';
import * as PushNotifications from 'appambit-push-notifications';
import App from './src/App';
import { name as appName } from './app.json';

if (Platform.OS === 'android') {
  AppRegistry.registerHeadlessTask(
    PushNotifications.BACKGROUND_NOTIFICATION_TASK,
    () => async (payload) => {
      console.log('Background notification (killed state):', payload);
    }
  );
}

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

Use AppRegistry.registerHeadlessTask with BACKGROUND_NOTIFICATION_TASK — not BackgroundFetch or any other API.


iOS Setup

Push Notifications Capability & APNs Entitlement

Enable Push Notifications in Xcode under your target's Signing & Capabilities tab. This automatically injects the aps-environment entitlement into your .entitlements file.

If you manage Runner.entitlements manually (e.g. via version control or CI), make sure this key is present — without it APNs will reject device registration and no token will ever be delivered:

<!-- ios/Runner/Runner.entitlements -->
<key>aps-environment</key>
<string>development</string>   <!-- use "production" for App Store builds -->

iOS Notification Service Extension (Rich Notifications)

To display rich notifications with image attachments, create a Notification Service Extension in Xcode.

  1. Create the extension: Go to File > New > Target, select Notification Service Extension, and give it a name (e.g. NotificationService).

  2. Add the pod to your Podfile outside the main target:

    target 'NotificationService' do
      pod 'AppAmbitPushNotificationsExtension', '~> 1.1.0'
    end

    Then run pod install under ios/.

  3. Subclass AppAmbitNotificationService in NotificationService.swift:

    import UserNotifications
    import AppAmbitPushNotificationsExtension
    
    class NotificationService: AppAmbitNotificationService {
      override func didReceive(
        _ request: UNNotificationRequest,
        withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
      ) {
        // Base class handles rich media download and attachment automatically.
        super.didReceive(request, withContentHandler: contentHandler)
      }
    
      override func serviceExtensionTimeWillExpire() {
        super.serviceExtensionTimeWillExpire()
      }
    }