@lazidog/expo-notification-extension
Version:
| [with FCM compatibility] The Expo Notification Service Extension plugin allows you to add a Notification Service Extension file while staying in the managed workflow.
69 lines (68 loc) • 3.76 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var config_plugins_1 = require("@expo/config-plugins");
var constants_1 = require("../constants");
/**
* Add Xcode target for the extension
* Create PBXGroup to organize the extension files in Xcode file explorer
*
*/
var withNotificationExtensionXcode = function (config) {
return (0, config_plugins_1.withXcodeProject)(config, function (newConfig) {
var _a;
var pbxProject = newConfig.modResults;
if (pbxProject.pbxTargetByName(constants_1.EXTENSION_NAME)) {
return newConfig;
}
// Create new PBXGroup for the extension
var extGroup = pbxProject.addPbxGroup(__spreadArray([], constants_1.EXT_FILES, true), constants_1.EXTENSION_NAME, constants_1.EXTENSION_NAME);
/**
* Add the new PBXGroup to the top level group.
* This makes the files / folder appear in the file explorer in Xcode.
*/
var groups = pbxProject.hash.project.objects.PBXGroup;
// biome-ignore lint/complexity/noForEach: <explanation>
Object.keys(groups).forEach(function (key) {
if (typeof groups[key] === "object" &&
groups[key].name === undefined &&
groups[key].path === undefined) {
pbxProject.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
var projObjects = pbxProject.hash.project.objects;
projObjects.PBXTargetDependency = projObjects.PBXTargetDependency || {};
projObjects.PBXContainerItemProxy = projObjects.PBXTargetDependency || {};
var target = pbxProject.addTarget(constants_1.EXTENSION_NAME, "app_extension", constants_1.EXTENSION_NAME, "".concat((_a = newConfig.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier, ".").concat(constants_1.EXTENSION_NAME));
/**
* Adds source file NotificationService.m to build phase to compile.
* Without this phase, the code wouldn’t be compiled into an executable, and the extension would do nothing
*/
pbxProject.addBuildPhase(["NotificationService.m"], "PBXSourcesBuildPhase", "Sources", target.uuid);
pbxProject.addBuildPhase([], "PBXResourcesBuildPhase", "Resources", target.uuid);
pbxProject.addBuildPhase([], "PBXFrameworksBuildPhase", "Frameworks", target.uuid);
var configurations = pbxProject.pbxXCBuildConfigurationSection();
for (var key in configurations) {
var buildSettingsObj = configurations[key].buildSettings;
if (typeof buildSettingsObj !== "undefined" &&
buildSettingsObj.PRODUCT_NAME === "\"".concat(constants_1.EXTENSION_NAME, "\"")) {
buildSettingsObj.CODE_SIGN_ENTITLEMENTS = "".concat(constants_1.EXTENSION_NAME, "/").concat(constants_1.EXTENSION_NAME, ".entitlements");
buildSettingsObj.CODE_SIGN_STYLE = "Automatic";
}
}
return newConfig;
});
};
exports.default = withNotificationExtensionXcode;