Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: xcode race condition fix #76

Merged
merged 9 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -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