Skip to content

Commit 1a85266

Browse files
committed
feat: add Purchase Connector support to Expo config plugin
- Add shouldUsePurchaseConnector flag support - Add automatic Podfile flag injection with conflict detection - Maintain backward compatibility with manual configurations - Support both shouldUseStrictMode and shouldUsePurchaseConnector flags Builds upon Swift AppDelegate support from PR #624
1 parent 011ef3a commit 1a85266

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

expo/withAppsFlyer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const withAppsFlyerIos = require('./withAppsFlyerIos');
2-
module.exports = function withAppsFlyer(config, { shouldUseStrictMode = false } = {}) {
3-
config = withAppsFlyerIos(config, shouldUseStrictMode);
4-
return config;
2+
3+
module.exports = function withAppsFlyer(config, {
4+
shouldUseStrictMode = false,
5+
shouldUsePurchaseConnector = false
6+
} = {}) {
7+
config = withAppsFlyerIos(config, { shouldUseStrictMode, shouldUsePurchaseConnector });
8+
return config;
59
};

expo/withAppsFlyerIos.js

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,37 +153,66 @@ Supported format: Expo SDK default template
153153
});
154154
};
155155

156-
function withPodfile(config, shouldUseStrictMode) {
156+
function withPodfile(config, shouldUseStrictMode, shouldUsePurchaseConnector) {
157157
return withDangerousMod(config, [
158158
'ios',
159159
async (config) => {
160160
const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
161161
const contents = fs.readFileSync(filePath, 'utf-8');
162162

163-
const mergedPodfileWithStrictMode = mergeContents({
164-
tag: 'AppsFlyer Strict Mode',
165-
src: contents,
166-
newSrc: `$RNAppsFlyerStrictMode=${shouldUseStrictMode}`,
167-
anchor: 'use_expo_modules!',
168-
offset: 0,
169-
comment: '#',
170-
});
171-
172-
if (!mergedPodfileWithStrictMode.didMerge) {
173-
console.log("ERROR: Cannot add AppsFlyer strict mode to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.");
174-
return config;
163+
let mergedContents = { contents, didMerge: true };
164+
165+
// Check if Strict Mode flag already exists
166+
if (!contents.includes('$RNAppsFlyerStrictMode')) {
167+
mergedContents = mergeContents({
168+
tag: 'AppsFlyer Strict Mode',
169+
src: mergedContents.contents,
170+
newSrc: `$RNAppsFlyerStrictMode=${shouldUseStrictMode}`,
171+
anchor: 'use_expo_modules!',
172+
offset: 0,
173+
comment: '#',
174+
});
175+
176+
if (!mergedContents.didMerge) {
177+
console.log("ERROR: Cannot add AppsFlyer strict mode to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.");
178+
return config;
179+
}
180+
} else {
181+
console.log("INFO: $RNAppsFlyerStrictMode already exists in Podfile, skipping auto-assignment.");
175182
}
176183

177-
fs.writeFileSync(filePath, mergedPodfileWithStrictMode.contents);
184+
// Check if Purchase Connector flag already exists
185+
if (!contents.includes('$AppsFlyerPurchaseConnector')) {
186+
mergedContents = mergeContents({
187+
tag: 'AppsFlyer Purchase Connector',
188+
src: mergedContents.contents,
189+
newSrc: `$AppsFlyerPurchaseConnector=${shouldUsePurchaseConnector}`,
190+
anchor: 'use_expo_modules!',
191+
offset: mergedContents.contents.includes('$RNAppsFlyerStrictMode') ? 1 : 0,
192+
comment: '#',
193+
});
194+
195+
if (!mergedContents.didMerge) {
196+
console.log("ERROR: Cannot add AppsFlyer Purchase Connector to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.");
197+
return config;
198+
}
199+
} else {
200+
console.log("INFO: $AppsFlyerPurchaseConnector already exists in Podfile, skipping auto-assignment.");
201+
}
202+
203+
fs.writeFileSync(filePath, mergedContents.contents);
178204

179205
return config;
180206
},
181207
]);
182208
}
183209

184-
module.exports = function withAppsFlyerIos(config, shouldUseStrictMode) {
185-
config = withPodfile(config, shouldUseStrictMode);
210+
module.exports = function withAppsFlyerIos(config, {
211+
shouldUseStrictMode = false,
212+
shouldUsePurchaseConnector = false
213+
} = {}) {
214+
config = withPodfile(config, shouldUseStrictMode, shouldUsePurchaseConnector);
186215
config = withIosBridgingHeader(config);
187216
config = withAppsFlyerAppDelegate(config);
188217
return config;
189-
};
218+
};

0 commit comments

Comments
 (0)