Skip to content

Commit

Permalink
fix: xcode race condition fix (#76)
Browse files Browse the repository at this point in the history
Co-authored-by: Callum Steele <callum@eucalyptus.vc>
  • Loading branch information
xtreem88 and euc-callum committed Jun 1, 2023
1 parent eba9520 commit ff136ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 21 additions & 20 deletions src/ios/withNotificationsXcodeProject.ts
@@ -1,5 +1,8 @@
import { ConfigPlugin, withXcodeProject } from '@expo/config-plugins';
import xcode from 'xcode';
import {
ConfigPlugin,
XcodeProject,
withXcodeProject,
} from '@expo/config-plugins';

import {
CIO_NOTIFICATION_TARGET_NAME,
Expand All @@ -18,31 +21,22 @@ const ENV_FILENAME = 'Env.swift';
const TARGETED_DEVICE_FAMILY = `"1,2"`;

const addNotificationServiceExtension = async (
options: CustomerIOPluginOptionsIOS
options: CustomerIOPluginOptionsIOS,
xcodeProject: XcodeProject
) => {
// iosPath and appName are predefined from Expo config.
// See function withCioNotificationsXcodeProject to get where the variabes are pulled from.
const { iosPath, appName } = options;

const projPath = `${iosPath}/${appName}.xcodeproj/project.pbxproj`;

const xcodeProject = xcode.project(projPath);

xcodeProject.parse(async function (err: Error) {
if (err) {
throw new Error(`Error parsing iOS project: ${JSON.stringify(err)}`);
}

try {
if (options.pushNotification) {
await addPushNotificationFile(options, xcodeProject);
}

if (options.pushNotification?.useRichPush) {
await addRichPushXcodeProj(options, xcodeProject);
}

FileManagement.writeFile(projPath, xcodeProject.writeSync());
});
return xcodeProject;
} catch (error: any) {
console.error(error);
return null;
}
};

export const withCioNotificationsXcodeProject: ConfigPlugin<
Expand Down Expand Up @@ -97,7 +91,14 @@ export const withCioNotificationsXcodeProject: ConfigPlugin<
pushNotification,
};

await addNotificationServiceExtension(options);
const modifiedProjectFile = await addNotificationServiceExtension(
options,
config.modResults
);

if (modifiedProjectFile) {
config.modResults = modifiedProjectFile;
}

return config;
});
Expand Down

0 comments on commit ff136ba

Please sign in to comment.