Skip to content

Commit

Permalink
Merge pull request #202 from OneSignal/idempotent-pbxgroup
Browse files Browse the repository at this point in the history
Move target check to top of function to avoid adding duped PBXGroup
  • Loading branch information
rgomezp authored Sep 29, 2023
2 parents cf59ea9 + abf76ad commit 1fb1899
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions onesignal/withOneSignalIos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,14 @@ const withOneSignalXcodeProject: ConfigPlugin<OneSignalPluginProps> = (config, p
return withXcodeProject(config, newConfig => {
const xcodeProject = newConfig.modResults

if (!!xcodeProject.pbxTargetByName(NSE_TARGET_NAME)) {
OneSignalLog.log(`${NSE_TARGET_NAME} already exists in project. Skipping...`);
return newConfig;
}

// Create new PBXGroup for the extension
const extGroup = xcodeProject.addPbxGroup([...NSE_EXT_FILES, NSE_SOURCE_FILE], NSE_TARGET_NAME, NSE_TARGET_NAME);

// Add the new PBXGroup to the top level group. This makes the
// files / folder appear in the file explorer in Xcode.
const groups = xcodeProject.hash.project.objects["PBXGroup"];
Expand All @@ -174,11 +179,6 @@ const withOneSignalXcodeProject: ConfigPlugin<OneSignalPluginProps> = (config, p
projObjects['PBXTargetDependency'] = projObjects['PBXTargetDependency'] || {};
projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {};

if (!!xcodeProject.pbxTargetByName(NSE_TARGET_NAME)) {
OneSignalLog.log(`${NSE_TARGET_NAME} already exists in project. Skipping...`);
return newConfig;
}

// Add the NSE target
// This adds PBXTargetDependency and PBXContainerItemProxy for you
const nseTarget = xcodeProject.addTarget(NSE_TARGET_NAME, "app_extension", NSE_TARGET_NAME, `${config.ios?.bundleIdentifier}.${NSE_TARGET_NAME}`);
Expand Down

0 comments on commit 1fb1899

Please sign in to comment.