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

expo-notifee-plugin

v1.0.7

Published

Plugin to create a Notification Service extension in order to let Notifee mutate remote notifications

Downloads

371

Readme

🖲 expo-notifee-plugin

Expo platforms GitHub npm

⭐️ Features

iOS

Android

🔧 Installation

Yarn:

yarn add expo-notifee-plugin

NPM:

npm install --save expo-notifee-plugin

🎛 Setup

  1. Add it to your plugins in your app.json file:
{
  "expo": {
    "plugins": [
      [
        "expo-notifee-plugin",
        {
          "developmentTeam": "MYDEVTEAMID"
        }
      ]
    ]
  }
}
  1. Run npx expo prebuild -p ios
  2. Run yarn ios

Types

If you use app.config.ts for example:


import { ExpoConfig } from 'expo/config';
import { TExpoNotifeeRemote } from 'expo-notifee-plugin';

const notifeeOptions: TExpoNotifeeRemote = {
  /**
   * Apple App Groups. If none specified, it will create one: `group.${bundleIdentifier}`.
   * @example appGroups: ['com.app.company']
   * @link https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_application-groups
   */
  appGroups: string[];
  /**
   * @description
   * Use a custom relative (from project root) path for the NotifeeNotificationService.
   * - You can adapt `expo-notifee-plugin/ios/NotifeeNotificationService.swift`
   * - Warning! It should be named `NotifeeNotificationService`! Doesn't matter if you use
   * Swift or Objective-C!
   *
   * @examples
   * - src/notifications/NotifeeNotificationService.swift
   * - src/notifications/NotifeeNotificationService.m
   */
  customNotificationServicePath?: string;
  developmentTeam: string;
  /**
   * An array containing the sound file names (including file extensions)
   * @example soundFiles: ['dm.aiff']
   * */
  soundFiles?: string[];
  /** Path of the folder that contains the sound. Relative to the app.config.js file.
   * @example soundFilesPath: 'assets/audio'
   */
  soundFilesPath?: string;
};

export const plugins: ExpoConfig['plugins'] = [
  'expo-localization',
  ['expo-screen-orientation', { initialOrientation: 'PORTRAIT_UP' }],
  '@react-native-firebase/app',
  ['expo-notifee-plugin', notifeeOptions],
];

🛸 Usage

Example with Firebase Node SDK:

import type {Notification} from '@notifee/react-native/src/types/Notification';
import {AndroidImportance} from '@notifee/react-native/src/types/NotificationAndroid';
import {MulticastMessage} from 'firebase-admin/lib/messaging/messaging-api';
import admin from '../src/firebase-admin';

/**
 * @link https://notifee.app/react-native/reference/notification
 */
const notifeeOptions: Notification = {
  title: 'Title',
  subtitle: 'Subtitle',
  body: 'Main body content of the notification',
  android: {
    channelId: 'default',
    importance: AndroidImportance.HIGH,
    lightUpScreen: true,
    pressAction: {
      id: 'default',
    },
    sound: 'default',
  },
  ios: {
    sound: 'default',
    // Adding `foregroundPresentationOptions` controls how to
    // behave when app is UP AND RUNNING, not terminated,
    // AND not in background!
    foregroundPresentationOptions: {
      badge: true,
      banner: true,
      list: true,
      sound: true,
    },
  },
};


/** 
 * @description Firebase Message
 * @link https://firebase.google.com/docs/reference/admin/node/firebase-admin.messaging.basemessage.md#basemessage_interface
 */
const message: MulticastMessage = {
  // ✅ We can continue using local/data-only notification for Android
  // 👍 while triggering iOS remote notifications from `apns`
  data: {notifee_options: JSON.stringify(notifeeOptions)},
  tokens: [],
  android: {
    priority: 'high', // Needed to trigger data-only notifications
  },
  apns: {
    payload: {
      notifee_options: notifeeOptions,
      aps: {
        alert: {
          // 🚧 This is needed to trigger an alert/remote notification only for iOS
          // 👍 but Android will continue using data-only notifications
          title: 'ANY_DUMMY_STRING',
        },
        mutableContent: true,
      },
    },
  },
};

try {
  admin.messaging().sendEachForMulticast(message)
  res.status(200).end();
} catch (e) {
  res.status(400).end();
}

🤔 What it does?

This plugin handles moving the necessary NotifeeNSE files into their respective iOS directories.

Steps

  1. Updates entitlements
  2. Sets the app group to group.<identifier> if applicable
  3. Adds the extension plist
  4. Adds the view controller
  5. Adds the NotifeeCore pod in Podfile
  6. Adds the sounds (if any) in the iOS project
  7. Updates the xcode project's build phases

🪲 Debugging

  • Notifee issues: https://github.com/invertase/notifee/pull/1118

📃 License

📃 This project is released under the MIT License.
💻 By contributing, you agree that your contributions will be licensed under its MIT License.

👏 Credits

Adapted from:

  • https://github.com/OneSignal/onesignal-expo-plugin/blob/main/onesignal/withOneSignalIos.ts

  • https://github.com/bluesky-social/social-app/tree/main/plugins/notificationsExtension

  • https://github.com/evennit/notifee-expo-plugin

  • https://github.com/andrew-levy/react-native-safari-extension

  • https://github.com/timedtext/expo-config-plugin-ios-share-extension/blob/master/src/withShareExtensionXcodeTarget.ts

🏆 Sponsors

| |
|---------------------------| | jetbrains100 |