Skip to content

Commit 885e311

Browse files
authored
Merge pull request #641 from AppsFlyerSDK/dev/DELIVERY-97312/Expo-SwiftAppDelegate
Expo swift app delegate
2 parents 011ef3a + 8e0aad3 commit 885e311

10 files changed

Lines changed: 100 additions & 30 deletions

File tree

Docs/RN_ExpoInstallation.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ expo install react-native-appsflyer
2222
...
2323
"plugins": [
2424
[
25-
"react-native-appsflyer",{}
25+
"react-native-appsflyer",
26+
{
27+
"shouldUseStrictMode": false, // optional – kids-apps strict mode
28+
"shouldUsePurchaseConnector": true // NEW – enables Purchase Connector
29+
}
2630
]
2731
],
2832
...
@@ -112,3 +116,10 @@ In v6.8.0 of the AppsFlyer SDK, we added the normal permission com.google.androi
112116
to allow the SDK to collect the Android Advertising ID on apps targeting API 33.
113117
If your app is targeting children, you need to revoke this permission to comply with Google's Data policy.
114118
You can read more about it [here](https://docs.expo.dev/guides/permissions/#android).
119+
120+
### Purchase Connector (optional)
121+
122+
Setting `"shouldUsePurchaseConnector": true` will:
123+
124+
* **iOS** – add the `PurchaseConnector` CocoaPod automatically
125+
* **Android** – add `appsflyer.enable_purchase_connector=true` to `gradle.properties`

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
1313
### <a id="plugin-build-for"> This plugin is built for
1414

15-
- Android AppsFlyer SDK **v6.17.0**
16-
- iOS AppsFlyer SDK **v6.17.1**
15+
- Android AppsFlyer SDK **v6.17.1**
16+
- iOS AppsFlyer SDK **v6.17.2**
1717
- Tested with React-Native **v0.62.0** (older versions might be supported)
1818

1919
## <a id="release-updates"> Release Updates

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ repositories {
7070
dependencies {
7171
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.10" // Add Kotlin standard library
7272
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
73-
api "com.appsflyer:af-android-sdk:${safeExtGet('appsflyerVersion', '6.17.0')}"
73+
api "com.appsflyer:af-android-sdk:${safeExtGet('appsflyerVersion', '6.17.1')}"
7474
implementation "com.android.installreferrer:installreferrer:${safeExtGet('installReferrerVersion', '2.2')}"
7575
if (includeConnector){
7676
implementation 'com.appsflyer:purchase-connector:2.1.1'

android/src/main/java/com/appsflyer/reactnative/RNAppsFlyerConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class RNAppsFlyerConstants {
88

9-
final static String PLUGIN_VERSION = "6.17.1";
9+
final static String PLUGIN_VERSION = "6.17.2";
1010
final static String NO_DEVKEY_FOUND = "No 'devKey' found or its empty";
1111
final static String UNKNOWN_ERROR = "AF Unknown Error";
1212
final static String SUCCESS = "Success";

expo/withAppsFlyer.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
const withAppsFlyerIos = require('./withAppsFlyerIos');
2-
module.exports = function withAppsFlyer(config, { shouldUseStrictMode = false } = {}) {
3-
config = withAppsFlyerIos(config, shouldUseStrictMode);
4-
return config;
2+
const withAppsFlyerAndroid = require('./withAppsFlyerAndroid');
3+
console.log('[AppsFlyerPlugin] Main plugin loaded');
4+
5+
module.exports = function withAppsFlyer(config, {
6+
shouldUseStrictMode = false,
7+
shouldUsePurchaseConnector = false
8+
} = {}) {
9+
config = withAppsFlyerIos(config, { shouldUseStrictMode, shouldUsePurchaseConnector });
10+
config = withAppsFlyerAndroid(config, { shouldUsePurchaseConnector });
11+
return config;
512
};

expo/withAppsFlyerAndroid.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { withGradleProperties } = require('@expo/config-plugins');
2+
3+
function addPurchaseConnectorFlag(config) {
4+
return withGradleProperties(config, (cfg) => {
5+
const props = cfg.modResults ?? [];
6+
const exists = props.some((p) => p.key === 'appsflyer.enable_purchase_connector');
7+
if (!exists) {
8+
props.push({ type: 'property', key: 'appsflyer.enable_purchase_connector', value: 'true' });
9+
} else {
10+
console.log('[AppsFlyerPlugin] Flag already present, no changes made');
11+
}
12+
return cfg;
13+
});
14+
}
15+
16+
module.exports = function withAppsFlyerAndroid(config, { shouldUsePurchaseConnector = false } = {}) {
17+
if (shouldUsePurchaseConnector) {
18+
config = addPurchaseConnectorFlag(config);
19+
} else {
20+
console.log('[AppsFlyerPlugin] Purchase Connector disabled, skipping gradle property injection');
21+
}
22+
return config;
23+
};

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+
};

ios/RNAppsFlyer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
@end
2323

2424

25-
static NSString *const kAppsFlyerPluginVersion = @"6.17.1";
25+
static NSString *const kAppsFlyerPluginVersion = @"6.17.2";
2626
static NSString *const NO_DEVKEY_FOUND = @"No 'devKey' found or its empty";
2727
static NSString *const NO_APPID_FOUND = @"No 'appId' found or its empty";
2828
static NSString *const NO_EVENT_NAME_FOUND = @"No 'eventName' found or its empty";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-appsflyer",
3-
"version": "6.17.1",
3+
"version": "6.17.2",
44
"description": "React Native Appsflyer plugin",
55
"main": "index.js",
66
"types": "index.d.ts",

react-native-appsflyer.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ Pod::Spec.new do |s|
3030
# AppsFlyerPurchaseConnector
3131
if defined?($AppsFlyerPurchaseConnector) && ($AppsFlyerPurchaseConnector == true)
3232
Pod::UI.puts "#{s.name}: Including PurchaseConnector."
33-
s.dependency 'PurchaseConnector', '6.17.1'
33+
s.dependency 'PurchaseConnector', '6.17.2'
3434
end
3535

3636
# AppsFlyerFramework
3737
if defined?($RNAppsFlyerStrictMode) && ($RNAppsFlyerStrictMode == true)
3838
Pod::UI.puts "#{s.name}: Using AppsFlyerFramework/Strict mode"
39-
s.dependency 'AppsFlyerFramework/Strict', '6.17.1'
39+
s.dependency 'AppsFlyerFramework/Strict', '6.17.2'
4040
s.xcconfig = {'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) AFSDK_NO_IDFA=1' }
4141
else
4242
if !defined?($RNAppsFlyerStrictMode)
4343
Pod::UI.puts "#{s.name}: Using default AppsFlyerFramework. You may require App Tracking Transparency. Not allowed for Kids apps."
4444
Pod::UI.puts "#{s.name}: You may set variable `$RNAppsFlyerStrictMode=true` in Podfile to use strict mode for kids apps."
4545
end
46-
s.dependency 'AppsFlyerFramework', '6.17.1'
46+
s.dependency 'AppsFlyerFramework', '6.17.2'
4747
end
4848
end

0 commit comments

Comments
 (0)