1.0.0 • Published 6 months ago

expo-nse-plugin v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Expo NSE Plugin

An Expo config plugin for iOS that allows you to easily add a Notification Service Extension to your project.

A lightweight, unrestricted alternative for creating NSE with Expo under a standard MIT license. No vendor lock-in, no usage limitations - just clean code you can use anywhere.

Scope

  • creation of the Notification Service Extension target inside your project
  • configurable Objective-C implementation and header files of the Notification Service Extension
  • configurable App Group identifier, bridging your application with the Notification Service Extension
  • automation of the Xcode pbxproj file modifications - build settings, groups, build phases and others
  • an option to provide your own code to be injected into App Delegate's imports fragment and into its didRegisterForRemoteNotificationsWithDeviceToken function signature

!IMPORTANT This config plugin does not serve as any kind of replacement of the Expo Notifications module. Instead, it builds on top of it. While Expo NSE Plugin exposes some configuration options that may overalp with the aforementioned module, ideally, you should use Expo Notifications to configure your app's notifications (both for iOS and Android) and then in case you need the NSE enhancement, add this config plugin to the mixture.

Provisioning profiles

This plugin does not handle anything related to the signing process and does not automate the process of choosing the provisioning profile for the NSE target. For this purpose it's probably best if you use Expo Application Services and its multitarget configuration.

Installation and usage

Add the package to your npm dependencies

npx expo install expo-nse-plugin

Config plugin setup

To setup, just add the config plugin to the plugins array of your app.json or app.config.js as shown below, then rebuild the app.

Simple:

{
  "expo": {
    ...
    "plugins": [
      ...,
      "expo-nse-plugin"
    ],
  }
}

Advanced:

{
  "expo": {
    ...
    "plugins": [
      ...,
      [
        "expo-nse-plugin",
        {
          "mode": "development",
          "appGroup": "group.com.github.pawicao.app",
          "backgroundModes": {
            "remoteNotifications": true,
            "fetch": true
          },
          "appDelegate": {
            "remoteNotificationsDelegate": "[SomeOtherService setPushIdentifier:deviceToken];",
            "imports": "#import \"SomeOtherService.h\""
          },
          "nse": {
            "mFilePath": "./my_path/to_a_custom_nse_implementation_file",
            "hFilePath": "./my_path/to_a_custom_nse_header_file",
            "bundleName": "NotificationServiceExtension",
          }
        }
      ]
    ],
  }
}

API documentation

All the options of the plugin configurable from the app.json / app.config.js file are listed below:

PropertyTypeRequiredDefaultDescription
mode"development" \| "production"No"development"Determines the APNs environment. Use development for testing and production for App Store builds
appGroupstringNoNoneThe App Group identifier used to share data between the main app and the NSE. Format: group.your.bundle.id
backgroundModes.remoteNotificationsbooleanNotrueEnables remote notifications background mode in your app's capabilities (if set to false, keeps as-is)
backgroundModes.fetchbooleanNofalseEnables background fetch capability in your app's capabilities (if set to false, keeps as-is)
appDelegate.remoteNotificationsDelegatestringNoNoneCustom code to be injected into the didRegisterForRemoteNotificationsWithDeviceToken method of your AppDelegate
appDelegate.importsstringNoNoneAdditional import statements to be added to your AppDelegate
nse.mFilePathstringNoDefault Xcode's NSE contentPath to a custom implementation file (.m) for the Notification Service Extension
nse.hFilePathstringNoDefault Xcode's NSE contentPath to a custom header file (.h) for the Notification Service Extension
nse.bundleNamestringNo"NotificationServiceExtension"The name of your Notification Service Extension target

Contributing & testing

PRs and feedback are more than welcome! If you see a way of extending this plugin's configuration options or capabilities, do let me know!

This plugin has not been thoroughly tested over different range of Xcode versions, I simply created it for my own use case. Therefore there's a chance that it may fail in some specific configurations of your particular project and your environment. If this is the case, feel free to raise an issue and I'll try to do something about it!

Refer to expo-module-scripts documentation for information about useful commands while developing the plugin.