Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

onesignal-expo-plugin

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onesignal-expo-plugin - npm Package Compare versions

Comparing version 1.0.0-beta1 to 1.0.0-beta10

app.plugin.js

26

build/onesignal/withOneSignalAndroid.js

@@ -9,22 +9,18 @@ "use strict";

const config_plugins_1 = require("@expo/config-plugins");
// ---------- ---------- ---------- ----------
const oneSignalGradle = `
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'`;
// ---------- ---------- ---------- ----------
const androidConstants_1 = require("../support/androidConstants");
const OneSignalLog_1 = require("../support/OneSignalLog");
const withGradleBuildConfig = (config) => {
return (0, config_plugins_1.withAppBuildGradle)(config, (newConfig) => {
newConfig.modResults.contents = `${oneSignalGradle.trimStart()}\n\n${newConfig.modResults.contents}`;
let { contents } = newConfig.modResults;
// make sure we haven't previously added dependencies
if (!contents.includes(androidConstants_1.ONESIGNAL_GRADLE)) {
contents = `${androidConstants_1.ONESIGNAL_GRADLE}\n${contents}`;
}
else {
OneSignalLog_1.OneSignalLog.log("OneSignal dependencies already added to build.gradle. Skipping...");
}
newConfig.modResults.contents = contents;
return newConfig;
});
};
// ---------- ---------- ---------- ----------
const withOneSignalAndroid = (config, props) => {

@@ -31,0 +27,0 @@ withGradleBuildConfig(config, props);

@@ -6,6 +6,33 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.withOneSignalIos = void 0;
exports.xcodeProjectAddNse = exports.withOneSignalIos = void 0;
const config_plugins_1 = require("@expo/config-plugins");
// ---------- ---------- ---------- ----------
const fs = __importStar(require("fs"));
const xcode_1 = __importDefault(require("xcode"));
const iosConstants_1 = require("../support/iosConstants");
const updatePodfile_1 = require("../support/updatePodfile");
const NseUpdaterManager_1 = __importDefault(require("../support/NseUpdaterManager"));
const OneSignalLog_1 = require("../support/OneSignalLog");
/**

@@ -15,5 +42,11 @@ * Add 'app-environment' record with current environment to '<project-name>.entitlements' file

*/
const withAppEnvironment = (config, { mode }) => {
const withAppEnvironment = (config, onesignalProps) => {
return (0, config_plugins_1.withEntitlementsPlist)(config, (newConfig) => {
newConfig.modResults['aps-environment'] = mode;
if ((onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.mode) == null) {
throw new Error(`
Missing required "mode" key in your app.json or app.config.js file for "onesignal-expo-plugin".
"mode" can be either "development" or "production".
Please see onesignal-expo-plugin's README.md for more details.`);
}
newConfig.modResults["aps-environment"] = onesignalProps.mode;
return newConfig;

@@ -27,7 +60,12 @@ });

const withRemoteNotificationsPermissions = (config) => {
const BACKGROUND_MODE_KEYS = ["remote-notification"];
return (0, config_plugins_1.withInfoPlist)(config, (newConfig) => {
newConfig.modResults.UIBackgroundModes = [
'external-accessory',
'remote-notifications',
];
if (!Array.isArray(newConfig.modResults.UIBackgroundModes)) {
newConfig.modResults.UIBackgroundModes = [];
}
for (const key of BACKGROUND_MODE_KEYS) {
if (!newConfig.modResults.UIBackgroundModes.includes(key)) {
newConfig.modResults.UIBackgroundModes.push(key);
}
}
return newConfig;

@@ -41,11 +79,32 @@ });

const withAppGroupPermissions = (config) => {
return (0, config_plugins_1.withEntitlementsPlist)(config, (newConfig) => {
const APP_GROUP_KEY = "com.apple.security.application-groups";
return (0, config_plugins_1.withEntitlementsPlist)(config, newConfig => {
var _a;
newConfig.modResults['com.apple.security.application-groups'] = [
`group.${((_a = newConfig === null || newConfig === void 0 ? void 0 : newConfig.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier) || ''}.onesignal`,
];
if (!Array.isArray(newConfig.modResults[APP_GROUP_KEY])) {
newConfig.modResults[APP_GROUP_KEY] = [];
}
let modResultsArray = newConfig.modResults[APP_GROUP_KEY];
let entitlement = `group.${((_a = newConfig === null || newConfig === void 0 ? void 0 : newConfig.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier) || ""}.onesignal`;
if (modResultsArray.indexOf(entitlement) !== -1) {
return newConfig;
}
modResultsArray.push(entitlement);
return newConfig;
});
};
// ---------- ---------- ---------- ----------
const withOneSignalNSE = (config, onesignalProps) => {
return (0, config_plugins_1.withXcodeProject)(config, async (props) => {
var _a, _b;
const options = {
iosPath: props.modRequest.platformProjectRoot,
bundleIdentifier: (_a = props.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier,
devTeam: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.devTeam,
bundleVersion: (_b = props.ios) === null || _b === void 0 ? void 0 : _b.buildNumber,
bundleShortVersion: props === null || props === void 0 ? void 0 : props.version,
iPhoneDeploymentTarget: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.iPhoneDeploymentTarget
};
xcodeProjectAddNse(props.modRequest.projectName || "", options, "node_modules/onesignal-expo-plugin/build/support/serviceExtensionFiles/");
return props;
});
};
const withOneSignalIos = (config, props) => {

@@ -55,4 +114,85 @@ withAppEnvironment(config, props);

withAppGroupPermissions(config, props);
withOneSignalNSE(config, props);
return config;
};
exports.withOneSignalIos = withOneSignalIos;
function xcodeProjectAddNse(appName, options, sourceDir) {
const { iosPath, devTeam, bundleIdentifier, bundleVersion, bundleShortVersion, iPhoneDeploymentTarget } = options;
(0, updatePodfile_1.updatePodfile)(iosPath);
NseUpdaterManager_1.default.updateNSEEntitlements(`group.${bundleIdentifier}.onesignal`);
NseUpdaterManager_1.default.updateNSEBundleVersion(bundleVersion !== null && bundleVersion !== void 0 ? bundleVersion : iosConstants_1.DEFAULT_BUNDLE_VERSION);
NseUpdaterManager_1.default.updateNSEBundleShortVersion(bundleShortVersion !== null && bundleShortVersion !== void 0 ? bundleShortVersion : iosConstants_1.DEFAULT_BUNDLE_SHORT_VERSION);
const projPath = `${iosPath}/${appName}.xcodeproj/project.pbxproj`;
const targetName = "OneSignalNotificationServiceExtension";
const extFiles = [
"NotificationService.h",
"NotificationService.m",
`${targetName}.entitlements`,
`${targetName}-Info.plist`
];
const xcodeProject = xcode_1.default.project(projPath);
xcodeProject.parse(function (err) {
if (err) {
OneSignalLog_1.OneSignalLog.log(`Error parsing iOS project: ${JSON.stringify(err)}`);
return;
}
// Copy in the extension files
fs.mkdirSync(`${iosPath}/${targetName}`, { recursive: true });
extFiles.forEach(function (extFile) {
let targetFile = `${iosPath}/${targetName}/${extFile}`;
try {
fs.createReadStream(`${sourceDir}${extFile}`).pipe(fs.createWriteStream(targetFile));
}
catch (err) {
OneSignalLog_1.OneSignalLog.log(err);
}
});
const projObjects = xcodeProject.hash.project.objects;
// Create new PBXGroup for the extension
let extGroup = xcodeProject.addPbxGroup(extFiles, targetName, targetName);
// Add the new PBXGroup to the top level group. This makes the
// files / folder appear in the file explorer in Xcode.
let groups = xcodeProject.hash.project.objects["PBXGroup"];
Object.keys(groups).forEach(function (key) {
if (groups[key].name === undefined) {
xcodeProject.addToPbxGroup(extGroup.uuid, key);
}
});
// WORK AROUND for codeProject.addTarget BUG
// Xcode projects don't contain these if there is only one target
// An upstream fix should be made to the code referenced in this link:
// - https://github.com/apache/cordova-node-xcode/blob/8b98cabc5978359db88dc9ff2d4c015cba40f150/lib/pbxProject.js#L860
projObjects['PBXTargetDependency'] = projObjects['PBXTargetDependency'] || {};
projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {};
if (!!xcodeProject.pbxTargetByName(targetName)) {
OneSignalLog_1.OneSignalLog.log(`${targetName} already exists in project. Skipping...`);
return;
}
// Add the NSE target
// This adds PBXTargetDependency and PBXContainerItemProxy for you
const nseTarget = xcodeProject.addTarget(targetName, "app_extension", targetName, `${bundleIdentifier}.${targetName}`);
// Add build phases to the new target
xcodeProject.addBuildPhase(["NotificationService.m"], "PBXSourcesBuildPhase", "Sources", nseTarget.uuid);
xcodeProject.addBuildPhase([], "PBXResourcesBuildPhase", "Resources", nseTarget.uuid);
xcodeProject.addBuildPhase([], "PBXFrameworksBuildPhase", "Frameworks", nseTarget.uuid);
// Edit the Deployment info of the new Target, only IphoneOS and Targeted Device Family
// However, can be more
let configurations = xcodeProject.pbxXCBuildConfigurationSection();
for (let key in configurations) {
if (typeof configurations[key].buildSettings !== "undefined" &&
configurations[key].buildSettings.PRODUCT_NAME == `"${targetName}"`) {
let buildSettingsObj = configurations[key].buildSettings;
buildSettingsObj.DEVELOPMENT_TEAM = devTeam;
buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET = iPhoneDeploymentTarget !== null && iPhoneDeploymentTarget !== void 0 ? iPhoneDeploymentTarget : iosConstants_1.IPHONEOS_DEPLOYMENT_TARGET;
buildSettingsObj.TARGETED_DEVICE_FAMILY = iosConstants_1.TARGETED_DEVICE_FAMILY;
buildSettingsObj.CODE_SIGN_ENTITLEMENTS = `${targetName}/${targetName}.entitlements`;
buildSettingsObj.CODE_SIGN_STYLE = "Automatic";
}
}
// Add development teams to both your target and the original project
xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam, nseTarget);
xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam);
fs.writeFileSync(projPath, xcodeProject.writeSync());
});
}
exports.xcodeProjectAddNse = xcodeProjectAddNse;

@@ -15,3 +15,4 @@ /**

mode: string;
iOsBundleIdentifier: string;
devTeam: string;
iPhoneDeploymentTarget: string;
};

@@ -18,0 +19,0 @@

@@ -7,23 +7,18 @@ /**

import { ConfigPlugin, withAppBuildGradle } from '@expo/config-plugins';
import { ONESIGNAL_GRADLE } from '../support/androidConstants';
import { OneSignalLog } from '../support/OneSignalLog';
import { OneSignalPluginProps } from './withOneSignal';
// ---------- ---------- ---------- ----------
const oneSignalGradle = `
buildscript {
repositories {
gradlePluginPortal()
const withGradleBuildConfig: ConfigPlugin<OneSignalPluginProps> = (config) => {
return withAppBuildGradle(config, (newConfig) => {
let { contents } = newConfig.modResults;
// make sure we haven't previously added dependencies
if (!contents.includes(ONESIGNAL_GRADLE)) {
contents = `${ONESIGNAL_GRADLE}\n${contents}`;
} else {
OneSignalLog.log("OneSignal dependencies already added to build.gradle. Skipping...");
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'`;
// ---------- ---------- ---------- ----------
const withGradleBuildConfig: ConfigPlugin<OneSignalPluginProps> = (config) => {
return withAppBuildGradle(config, (newConfig) => {
newConfig.modResults.contents = `${oneSignalGradle.trimStart()}\n\n${
newConfig.modResults.contents
}`;
newConfig.modResults.contents = contents;
return newConfig;

@@ -33,3 +28,2 @@ });

// ---------- ---------- ---------- ----------
export const withOneSignalAndroid: ConfigPlugin<OneSignalPluginProps> = (

@@ -36,0 +30,0 @@ config,

@@ -10,6 +10,26 @@ /**

withInfoPlist,
} from '@expo/config-plugins';
import { OneSignalPluginProps } from './withOneSignal';
withXcodeProject,
} from "@expo/config-plugins";
import { OneSignalPluginProps } from "./withOneSignal";
import * as fs from 'fs';
import xcode from 'xcode';
import {
DEFAULT_BUNDLE_SHORT_VERSION,
DEFAULT_BUNDLE_VERSION,
IPHONEOS_DEPLOYMENT_TARGET,
TARGETED_DEVICE_FAMILY
} from "../support/iosConstants";
import { updatePodfile } from "../support/updatePodfile";
import NseUpdaterManager from "../support/NseUpdaterManager";
import { OneSignalLog } from "../support/OneSignalLog";
// ---------- ---------- ---------- ----------
/* I N T E R F A C E S */
interface PluginOptions {
iosPath: string,
devTeam?: string,
bundleVersion?: string,
bundleShortVersion?: string,
bundleIdentifier?: string,
iPhoneDeploymentTarget?: string
}

@@ -22,6 +42,13 @@ /**

config,
{ mode },
onesignalProps
) => {
return withEntitlementsPlist(config, (newConfig) => {
newConfig.modResults['aps-environment'] = mode;
if (onesignalProps?.mode == null) {
throw new Error(`
Missing required "mode" key in your app.json or app.config.js file for "onesignal-expo-plugin".
"mode" can be either "development" or "production".
Please see onesignal-expo-plugin's README.md for more details.`
)
}
newConfig.modResults["aps-environment"] = onesignalProps.mode;
return newConfig;

@@ -36,9 +63,15 @@ });

const withRemoteNotificationsPermissions: ConfigPlugin<OneSignalPluginProps> = (
config,
config
) => {
const BACKGROUND_MODE_KEYS = ["remote-notification"];
return withInfoPlist(config, (newConfig) => {
newConfig.modResults.UIBackgroundModes = [
'external-accessory',
'remote-notifications',
];
if (!Array.isArray(newConfig.modResults.UIBackgroundModes)) {
newConfig.modResults.UIBackgroundModes = [];
}
for (const key of BACKGROUND_MODE_KEYS) {
if (!newConfig.modResults.UIBackgroundModes.includes(key)) {
newConfig.modResults.UIBackgroundModes.push(key);
}
}
return newConfig;

@@ -53,8 +86,16 @@ });

const withAppGroupPermissions: ConfigPlugin<OneSignalPluginProps> = (
config,
config
) => {
return withEntitlementsPlist(config, (newConfig) => {
newConfig.modResults['com.apple.security.application-groups'] = [
`group.${newConfig?.ios?.bundleIdentifier || ''}.onesignal`,
];
const APP_GROUP_KEY = "com.apple.security.application-groups";
return withEntitlementsPlist(config, newConfig => {
if (!Array.isArray(newConfig.modResults[APP_GROUP_KEY])) {
newConfig.modResults[APP_GROUP_KEY] = [];
}
let modResultsArray = (newConfig.modResults[APP_GROUP_KEY] as Array<any>);
let entitlement = `group.${newConfig?.ios?.bundleIdentifier || ""}.onesignal`;
if (modResultsArray.indexOf(entitlement) !== -1) {
return newConfig;
}
modResultsArray.push(entitlement);
return newConfig;

@@ -64,6 +105,26 @@ });

// ---------- ---------- ---------- ----------
const withOneSignalNSE: ConfigPlugin<OneSignalPluginProps> = (config, onesignalProps) => {
return withXcodeProject(config, async props => {
const options: PluginOptions = {
iosPath: props.modRequest.platformProjectRoot,
bundleIdentifier: props.ios?.bundleIdentifier,
devTeam: onesignalProps?.devTeam,
bundleVersion: props.ios?.buildNumber,
bundleShortVersion: props?.version,
iPhoneDeploymentTarget: onesignalProps?.iPhoneDeploymentTarget
};
xcodeProjectAddNse(
props.modRequest.projectName || "",
options,
"node_modules/onesignal-expo-plugin/build/support/serviceExtensionFiles/"
);
return props;
});
}
export const withOneSignalIos: ConfigPlugin<OneSignalPluginProps> = (
config,
props,
props
) => {

@@ -73,4 +134,120 @@ withAppEnvironment(config, props);

withAppGroupPermissions(config, props);
withOneSignalNSE(config, props);
return config;
};
export function xcodeProjectAddNse(
appName: string,
options: PluginOptions,
sourceDir: string
): void {
const { iosPath, devTeam, bundleIdentifier, bundleVersion, bundleShortVersion, iPhoneDeploymentTarget } = options;
updatePodfile(iosPath);
NseUpdaterManager.updateNSEEntitlements(`group.${bundleIdentifier}.onesignal`)
NseUpdaterManager.updateNSEBundleVersion(bundleVersion ?? DEFAULT_BUNDLE_VERSION);
NseUpdaterManager.updateNSEBundleShortVersion(bundleShortVersion ?? DEFAULT_BUNDLE_SHORT_VERSION);
const projPath = `${iosPath}/${appName}.xcodeproj/project.pbxproj`;
const targetName = "OneSignalNotificationServiceExtension";
const extFiles = [
"NotificationService.h",
"NotificationService.m",
`${targetName}.entitlements`,
`${targetName}-Info.plist`
];
const xcodeProject = xcode.project(projPath);
xcodeProject.parse(function(err: Error) {
if (err) {
OneSignalLog.log(`Error parsing iOS project: ${JSON.stringify(err)}`);
return;
}
// Copy in the extension files
fs.mkdirSync(`${iosPath}/${targetName}`, { recursive: true });
extFiles.forEach(function (extFile) {
let targetFile = `${iosPath}/${targetName}/${extFile}`;
try {
fs.createReadStream(`${sourceDir}${extFile}`).pipe(
fs.createWriteStream(targetFile)
);
} catch (err) {
OneSignalLog.log(err as string);
}
});
const projObjects = xcodeProject.hash.project.objects;
// Create new PBXGroup for the extension
let extGroup = xcodeProject.addPbxGroup(extFiles, targetName, targetName);
// Add the new PBXGroup to the top level group. This makes the
// files / folder appear in the file explorer in Xcode.
let groups = xcodeProject.hash.project.objects["PBXGroup"];
Object.keys(groups).forEach(function (key) {
if (groups[key].name === undefined) {
xcodeProject.addToPbxGroup(extGroup.uuid, key);
}
});
// WORK AROUND for codeProject.addTarget BUG
// Xcode projects don't contain these if there is only one target
// An upstream fix should be made to the code referenced in this link:
// - https://github.com/apache/cordova-node-xcode/blob/8b98cabc5978359db88dc9ff2d4c015cba40f150/lib/pbxProject.js#L860
projObjects['PBXTargetDependency'] = projObjects['PBXTargetDependency'] || {};
projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {};
if (!!xcodeProject.pbxTargetByName(targetName)) {
OneSignalLog.log(`${targetName} already exists in project. Skipping...`);
return;
}
// Add the NSE target
// This adds PBXTargetDependency and PBXContainerItemProxy for you
const nseTarget = xcodeProject.addTarget(targetName, "app_extension", targetName, `${bundleIdentifier}.${targetName}`);
// Add build phases to the new target
xcodeProject.addBuildPhase(
["NotificationService.m"],
"PBXSourcesBuildPhase",
"Sources",
nseTarget.uuid
);
xcodeProject.addBuildPhase([], "PBXResourcesBuildPhase", "Resources", nseTarget.uuid);
xcodeProject.addBuildPhase(
[],
"PBXFrameworksBuildPhase",
"Frameworks",
nseTarget.uuid
);
// Edit the Deployment info of the new Target, only IphoneOS and Targeted Device Family
// However, can be more
let configurations = xcodeProject.pbxXCBuildConfigurationSection();
for (let key in configurations) {
if (
typeof configurations[key].buildSettings !== "undefined" &&
configurations[key].buildSettings.PRODUCT_NAME == `"${targetName}"`
) {
let buildSettingsObj = configurations[key].buildSettings;
buildSettingsObj.DEVELOPMENT_TEAM = devTeam;
buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET = iPhoneDeploymentTarget ?? IPHONEOS_DEPLOYMENT_TARGET;
buildSettingsObj.TARGETED_DEVICE_FAMILY = TARGETED_DEVICE_FAMILY;
buildSettingsObj.CODE_SIGN_ENTITLEMENTS = `${targetName}/${targetName}.entitlements`;
buildSettingsObj.CODE_SIGN_STYLE = "Automatic";
}
}
// Add development teams to both your target and the original project
xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam, nseTarget);
xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam);
fs.writeFileSync(projPath, xcodeProject.writeSync());
})
}
{
"name": "onesignal-expo-plugin",
"version": "1.0.0-beta1",
"version": "1.0.0-beta10",
"description": "The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.",
"main": "build/withOneSignal.js",
"main": "./app.plugin.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"build": "rm -rf build && tsc && cp -a support/serviceExtensionFiles build/support/",
"prepare": "yarn run build"

@@ -25,3 +25,4 @@ },

"Karen Grigoryan",
"Rodrigo Gomez-Palacio"
"Rodrigo Gomez-Palacio",
"Charlie Cruzan"
],

@@ -37,3 +38,6 @@ "license": "MIT",

},
"dependencies": {}
"dependencies": {
"react-native-onesignal": "^4.3.1",
"xcode": "^3.0.1"
}
}
<h1 align="center">Welcome to onesignal-expo-plugin 👋</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0--beta1-blue.svg?cacheSeconds=2592000" />
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0--beta10-blue.svg?cacheSeconds=2592000" />
<a href="https://github.com/OneSignal/onesignal-expo-plugin#readme" target="_blank">

@@ -10,5 +10,2 @@ <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />

</a>
<a href="https://github.com/OneSignal/onesignal-expo-plugin/blob/master/LICENSE" target="_blank">
<img alt="License: MIT" src="https://img.shields.io/github/license/OneSignal/onesignal-expo-plugin" />
</a>
<a href="https://twitter.com/onesignal" target="_blank">

@@ -21,4 +18,16 @@ <img alt="Twitter: onesignal" src="https://img.shields.io/twitter/follow/onesignal.svg?style=social" />

### 🏠 [Homepage](https://github.com/OneSignal/onesignal-expo-plugin#readme)
* 🏠 [Homepage](https://github.com/OneSignal/onesignal-expo-plugin#readme)
* 🖤 [npm](https://www.npmjs.com/package/onesignal-expo-plugin)
## 🚧 In Beta 🚧
## Overview
This plugin is an [Expo Config Plugin](https://docs.expo.dev/guides/config-plugins/). It extends the Expo config to allow customizing the prebuild phase of managed workflow builds (no need to eject to a bare workflow). For the purposes of OneSignal integration, the plugin facilitates automatically generating/configuring the necessary native code files needed to get the [OneSignal React-Native SDK](https://github.com/OneSignal/react-native-onesignal) to work. You can think of adding a plugin as adding custom native code.
## Supported environments:
* [The Expo run commands](https://docs.expo.dev/workflow/customizing/) (`expo run:[android|ios]`)
* [Custom clients](https://blog.expo.dev/introducing-custom-development-clients-5a2c79a9ddf8)
* [EAS Build](https://docs.expo.dev/build/introduction/)
---
## Install

@@ -28,14 +37,19 @@

expo install onesignal-expo-plugin
yarn add react-native-onesignal
```
**Note:** this does not install the [OneSignal SDK](https://github.com/OneSignal/react-native-onesignal).
## Configuration in app.json / app.config.js
### Plugin
Add the `withOneSignal.js` file to the [plugin array](https://docs.expo.dev/versions/latest/config/app/):
Add the plugin to the [plugin array](https://docs.expo.dev/versions/latest/config/app/):
**app.json**
```json
{
"plugins": [
"./node_modules/onesignal-expo-plugin/build/onesignal/withOneSignal.js"
[
"onesignal-expo-plugin",
{
"mode": "development",
}
]
]

@@ -45,2 +59,28 @@ }

or
**app.config.js**
```js
export default {
...
plugins: [
[
"onesignal-expo-plugin",
{
mode: "development",
}
]
]
};
```
#### Plugin Prop
You can pass props to the plugin config object to configure:
| Plugin Prop | | |
|--------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mode` | **required** | Used to configure [APNs environment](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment) entitlement. `"development"` or `"production"` |
| `devTeam` | optional | Used to configure Apple Team ID. You can find your Apple Team ID by running `expo credentials:manager` e.g: `"91SW8A37CR"` |
| `iPhoneDeploymentTarget` | optional | Target `IPHONEOS_DEPLOYMENT_TARGET` value to be used when adding the iOS [NSE](https://documentation.onesignal.com/docs/service-extensions). A deployment target is nothing more than the minimum version of the operating system the application can run on. This value should match the value in your Podfile e.g: `"12.0"`. |
### OneSignal App ID

@@ -61,2 +101,3 @@ Add your OneSignal App ID to your [Expo constants via the `extra` param](https://docs.expo.dev/versions/latest/config/app/):

```js
import OneSignal from 'react-native-onesignal';
import Constants from "expo-constants";

@@ -66,2 +107,29 @@ OneSignal.setAppId(Constants.manifest.extra.oneSignalAppId);

Alternatively, pass the app ID directly to the function:
```js
OneSignal.setAppId("YOUR-ONESIGNAL-APP-ID");
```
### Versioning
In your configuration file, make sure you set:
| Property | Details |
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `version` | Your app version. Corresponds to `CFBundleShortVersionString` on iOS. This value will be used in your NSE* target's plist file. |
| `ios.buildNumber` | Build number for your iOS standalone app. Corresponds to `CFBundleVersion` and must match Apple's specified format. This value will be used in your NSE* target's plist file. |
\* NSE = Notification Service Extension. Learn more about the NSE [here](https://documentation.onesignal.com/docs/service-extensions).
## Run
```sh
$ expo prebuild --clean
# Build your native iOS project
$ expo run:ios
# Build your native Android project
$ expo run:android
```
---

@@ -87,2 +155,2 @@

Copyright © 2021 [OneSignal](https://github.com/OneSignal).<br />
This project is [MIT](https://github.com/OneSignal/onesignal-expo-plugin/blob/master/LICENSE) licensed.
This project is [MIT](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/LICENSE) licensed.

@@ -13,4 +13,5 @@ {

"**/__mocks__/*",
"**/__tests__/*"
"**/__tests__/*",
"examples"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc