Skip to content

Instantly share code, notes, and snippets.

@jpudysz
Created February 24, 2024 11:33
Show Gist options
  • Save jpudysz/e6525502af75bf63c548e097d1d2274b to your computer and use it in GitHub Desktop.
Save jpudysz/e6525502af75bf63c548e097d1d2274b to your computer and use it in GitHub Desktop.
Inject iOS17 Live Activity Intents to expo-apple-targets (Add target to any file)
diff --git a/node_modules/@bacons/apple-targets/build/withXcodeChanges.js b/node_modules/@bacons/apple-targets/build/withXcodeChanges.js
index ef64d1b..4813a52 100644
--- a/node_modules/@bacons/apple-targets/build/withXcodeChanges.js
+++ b/node_modules/@bacons/apple-targets/build/withXcodeChanges.js
@@ -12,6 +12,7 @@ const target_1 = require("./target");
const XCBuildConfiguration_json_1 = __importDefault(require("./template/XCBuildConfiguration.json"));
const TemplateBuildSettings = XCBuildConfiguration_json_1.default;
const withXcparse_1 = require("./withXcparse");
+const injectWidgetIntentsToMainTarget = require("../../../../plugins/withWidgetIntents");
const withXcodeChanges = (config, props) => {
return (0, withXcparse_1.withXcodeProjectBeta)(config, (config) => {
// @ts-ignore
@@ -838,6 +839,10 @@ async function applyXcodeChanges(config, project, props) {
widgetTarget.createBuildPhase(xcode_1.PBXResourcesBuildPhase, {
files: [...assetFiles, ...resAssets],
});
+
+ // inject intents to main target
+ injectWidgetIntentsToMainTarget(xcode_1, project, swiftFiles);
+
const containerItemProxy = xcode_1.PBXContainerItemProxy.create(project, {
containerPortal: project.rootObject,
proxyType: 1,
// Since expo-apple-targets uses a mod for targets, we can't run any plugin because mods are asynchronous and run at the end
// Let's create some helper functions and call them with patch-package
// register here all app intents
const intents = [
"CaptureHandler.swift",
"PauseHandler.swift",
"StartHandler.swift",
"OpenControllerHandler.swift"
]
// this function will be called from @bacon/bacon-targets
const injectWidgetIntentsToMainTarget = (xcode, project, widgetSwiftFiles) => {
// create new PBXBuildFile reference for each intent, it will be auto-added to PbxBuildFileSection
const pbxBuildIntents = widgetSwiftFiles
.filter(file => intents.includes(file.props.fileRef.props.path))
.map(file => xcode.PBXBuildFile.create(project, {
fileRef: file.props.fileRef
}))
const rootTarget = project.rootObject.getMainAppTarget()
const rootTargetBuildPhase = rootTarget.getBuildPhase(xcode.PBXSourcesBuildPhase)
const files = [
...pbxBuildIntents,
...rootTargetBuildPhase.props.files
]
rootTargetBuildPhase.props.files = files
}
module.exports = injectWidgetIntentsToMainTarget
@erlinghaugstad
Copy link

Yes i did. I had to patch the file even further to add m files to the files included by the bacons apple target:

--- node_modules/@bacons/apple-targets/build/withXcodeChanges.js.orig	2024-10-21 00:00:00.000000000 +0000
+++ node_modules/@bacons/apple-targets/build/withXcodeChanges.js	2024-10-21 00:01:00.000000000 +0000
@@ -304,7 +304,7 @@
     }
     // Build Files
     // NOTE: Single-level only
-    const swiftFiles = (0, glob_1.sync)("*.swift", {
+    const swiftFiles = (0, glob_1.sync)("*.{swift,m}", {
         absolute: true,
         cwd: magicCwd,
     }).map((file) => {

And also add placeholder files to my widget xcproj: https://www.reactnative.university/blog/live-activities-interactions#resolving-xcode-issues-with-an-intent-placeholder.

Hope that helps you along @julian-gargicevich!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment