Skip to content

Commit 4437501

Browse files
committed
chore: remove tab
1 parent 9a14701 commit 4437501

1 file changed

Lines changed: 84 additions & 84 deletions

File tree

expo/withAppsFlyerIos.js

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,87 @@ const fs = require('fs');
55
const path = require('path');
66

77
function modifyObjcAppDelegate(appDelegate) {
8-
const RNAPPSFLYER_IMPORT = `#import <RNAppsFlyer.h>\n`;
9-
const RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER = `- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {`;
10-
const RNAPPSFLYER_OPENURL_IDENTIFIER = `- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {`;
11-
const RNAPPSFLYER_CONTINUE_USER_ACTIVITY_CODE = `[[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler];\n`;
12-
const RNAPPSFLYER_OPENURL_CODE = `[[AppsFlyerAttribution shared] handleOpenUrl:url options:options];\n`;
13-
14-
if (!appDelegate.includes(RNAPPSFLYER_IMPORT)) {
15-
appDelegate = RNAPPSFLYER_IMPORT + appDelegate;
16-
}
17-
if (appDelegate.includes(RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER) && !appDelegate.includes(RNAPPSFLYER_CONTINUE_USER_ACTIVITY_CODE)) {
18-
const block = RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER + '\n' + RNAPPSFLYER_CONTINUE_USER_ACTIVITY_CODE;
19-
appDelegate = appDelegate.replace(RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER, block);
20-
} else {
21-
WarningAggregator.addWarningIOS('withAppsFlyerAppDelegate', "Failed to detect continueUserActivity in AppDelegate or AppsFlyer's delegate method already exists");
22-
}
23-
if (appDelegate.includes(RNAPPSFLYER_OPENURL_IDENTIFIER) && !appDelegate.includes(RNAPPSFLYER_OPENURL_CODE)) {
24-
const block = RNAPPSFLYER_OPENURL_IDENTIFIER + '\n' + RNAPPSFLYER_OPENURL_CODE;
25-
appDelegate = appDelegate.replace(RNAPPSFLYER_OPENURL_IDENTIFIER, block);
26-
} else {
27-
WarningAggregator.addWarningIOS('withAppsFlyerAppDelegate', "Failed to detect openURL in AppDelegate or AppsFlyer's delegate method already exists");
28-
}
29-
return appDelegate;
8+
const RNAPPSFLYER_IMPORT = `#import <RNAppsFlyer.h>\n`;
9+
const RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER = `- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {`;
10+
const RNAPPSFLYER_OPENURL_IDENTIFIER = `- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {`;
11+
const RNAPPSFLYER_CONTINUE_USER_ACTIVITY_CODE = `[[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler];\n`;
12+
const RNAPPSFLYER_OPENURL_CODE = `[[AppsFlyerAttribution shared] handleOpenUrl:url options:options];\n`;
13+
14+
if (!appDelegate.includes(RNAPPSFLYER_IMPORT)) {
15+
appDelegate = RNAPPSFLYER_IMPORT + appDelegate;
16+
}
17+
if (appDelegate.includes(RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER) && !appDelegate.includes(RNAPPSFLYER_CONTINUE_USER_ACTIVITY_CODE)) {
18+
const block = RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER + '\n' + RNAPPSFLYER_CONTINUE_USER_ACTIVITY_CODE;
19+
appDelegate = appDelegate.replace(RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER, block);
20+
} else {
21+
WarningAggregator.addWarningIOS('withAppsFlyerAppDelegate', "Failed to detect continueUserActivity in AppDelegate or AppsFlyer's delegate method already exists");
22+
}
23+
if (appDelegate.includes(RNAPPSFLYER_OPENURL_IDENTIFIER) && !appDelegate.includes(RNAPPSFLYER_OPENURL_CODE)) {
24+
const block = RNAPPSFLYER_OPENURL_IDENTIFIER + '\n' + RNAPPSFLYER_OPENURL_CODE;
25+
appDelegate = appDelegate.replace(RNAPPSFLYER_OPENURL_IDENTIFIER, block);
26+
} else {
27+
WarningAggregator.addWarningIOS('withAppsFlyerAppDelegate', "Failed to detect openURL in AppDelegate or AppsFlyer's delegate method already exists");
28+
}
29+
return appDelegate;
3030
}
3131

3232
function modifySwiftAppDelegate(appDelegateContents) {
33-
const SWIFT_OPENURL_IDENTIFIER = ` public override func application(
33+
const SWIFT_OPENURL_IDENTIFIER = ` public override func application(
3434
_ app: UIApplication,
3535
open url: URL,
3636
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
3737
) -> Bool {`;
38-
const RNAPPSFLYER_SWIFT_OPENURL_CODE = 'AppsFlyerAttribution.shared().handleOpen(url, options: options)';
38+
const RNAPPSFLYER_SWIFT_OPENURL_CODE = 'AppsFlyerAttribution.shared().handleOpen(url, options: options)';
3939

40-
const SWIFT_CONTINUE_USER_ACTIVITY_IDENTIFIER = ` public override func application(
40+
const SWIFT_CONTINUE_USER_ACTIVITY_IDENTIFIER = ` public override func application(
4141
_ application: UIApplication,
4242
continue userActivity: NSUserActivity,
4343
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
4444
) -> Bool {`;
45-
const RNAPPSFLYER_SWIFT_CONTINUE_USER_ACTIVITY_CODE = 'AppsFlyerAttribution.shared().continue(userActivity, restorationHandler: nil)';
45+
const RNAPPSFLYER_SWIFT_CONTINUE_USER_ACTIVITY_CODE = 'AppsFlyerAttribution.shared().continue(userActivity, restorationHandler: nil)';
4646

4747
if (appDelegateContents.includes(SWIFT_OPENURL_IDENTIFIER) && !appDelegateContents.includes(RNAPPSFLYER_SWIFT_OPENURL_CODE)) {
48-
appDelegateContents = appDelegateContents.replace(SWIFT_OPENURL_IDENTIFIER, `${SWIFT_OPENURL_IDENTIFIER}\n ${RNAPPSFLYER_SWIFT_OPENURL_CODE}`);
48+
appDelegateContents = appDelegateContents.replace(SWIFT_OPENURL_IDENTIFIER, `${SWIFT_OPENURL_IDENTIFIER}\n ${RNAPPSFLYER_SWIFT_OPENURL_CODE}`);
4949
}
5050

51-
if (appDelegateContents.includes(SWIFT_CONTINUE_USER_ACTIVITY_IDENTIFIER) && !appDelegateContents.includes(RNAPPSFLYER_SWIFT_CONTINUE_USER_ACTIVITY_CODE)) {
52-
appDelegateContents = appDelegateContents.replace(SWIFT_CONTINUE_USER_ACTIVITY_IDENTIFIER, `${SWIFT_CONTINUE_USER_ACTIVITY_IDENTIFIER}\n ${RNAPPSFLYER_SWIFT_CONTINUE_USER_ACTIVITY_CODE}`);
53-
}
51+
if (appDelegateContents.includes(SWIFT_CONTINUE_USER_ACTIVITY_IDENTIFIER) && !appDelegateContents.includes(RNAPPSFLYER_SWIFT_CONTINUE_USER_ACTIVITY_CODE)) {
52+
appDelegateContents = appDelegateContents.replace(SWIFT_CONTINUE_USER_ACTIVITY_IDENTIFIER, `${SWIFT_CONTINUE_USER_ACTIVITY_IDENTIFIER}\n ${RNAPPSFLYER_SWIFT_CONTINUE_USER_ACTIVITY_CODE}`);
53+
}
5454

55-
if (!appDelegateContents.includes(RNAPPSFLYER_SWIFT_OPENURL_CODE) || !appDelegateContents.includes(RNAPPSFLYER_SWIFT_CONTINUE_USER_ACTIVITY_CODE)) {
56-
WarningAggregator.addWarningIOS(
57-
'withAppsFlyerAppDelegate',
55+
if (!appDelegateContents.includes(RNAPPSFLYER_SWIFT_OPENURL_CODE) || !appDelegateContents.includes(RNAPPSFLYER_SWIFT_CONTINUE_USER_ACTIVITY_CODE)) {
56+
WarningAggregator.addWarningIOS(
57+
'withAppsFlyerAppDelegate',
5858
`
5959
Automatic Swift AppDelegate modification failed.
6060
Please add AppsFlyer integration manually:
6161
6262
1. Add this to your openURL method:
63-
AppsFlyerAttribution.shared().handleOpen(url, options: options)
63+
AppsFlyerAttribution.shared().handleOpen(url, options: options)
6464
6565
2. Add this to your continueUserActivity method:
66-
AppsFlyerAttribution.shared().continue(userActivity, restorationHandler: nil)
67-
66+
AppsFlyerAttribution.shared().continue(userActivity, restorationHandler: nil)
67+
6868
Supported format: Expo SDK default template
6969
`
70-
);
71-
}
70+
);
71+
}
7272

73-
return appDelegateContents;
73+
return appDelegateContents;
7474
}
7575

7676
function withAppsFlyerAppDelegate(config) {
77-
return withAppDelegate(config, (config) => {
78-
const language = config.modResults.language;
79-
80-
if (['objc', 'objcpp'].includes(language)) {
81-
config.modResults.contents = modifyObjcAppDelegate(config.modResults.contents);
82-
} else if (language === 'swift') {
83-
config.modResults.contents = modifySwiftAppDelegate(config.modResults.contents);
84-
} else {
85-
WarningAggregator.addWarningIOS('withAppsFlyerAppDelegate', `${language} AppDelegate file is not supported yet`);
86-
}
87-
return config;
88-
});
77+
return withAppDelegate(config, (config) => {
78+
const language = config.modResults.language;
79+
80+
if (['objc', 'objcpp'].includes(language)) {
81+
config.modResults.contents = modifyObjcAppDelegate(config.modResults.contents);
82+
} else if (language === 'swift') {
83+
config.modResults.contents = modifySwiftAppDelegate(config.modResults.contents);
84+
} else {
85+
WarningAggregator.addWarningIOS('withAppsFlyerAppDelegate', `${language} AppDelegate file is not supported yet`);
86+
}
87+
return config;
88+
});
8989
}
9090

9191
function withIosBridgingHeader(config) {
@@ -112,16 +112,16 @@ function withIosBridgingHeader(config) {
112112
fs.writeFileSync(bridgingHeaderPath, content);
113113
}
114114
} else {
115-
WarningAggregator.addWarningIOS(
116-
'withIosBridgingHeader',
115+
WarningAggregator.addWarningIOS(
116+
'withIosBridgingHeader',
117117
`
118118
Failed to detect ${bridgingHeaderPath} file. Please add AppsFlyer integration manually:
119119
#import <RNAppsFlyer.h>
120120
121121
Supported format: Expo SDK default template
122122
`
123-
);
124-
}
123+
);
124+
}
125125

126126
return config;
127127
}
@@ -132,36 +132,36 @@ Supported format: Expo SDK default template
132132
};
133133

134134
function withPodfile(config, shouldUseStrictMode) {
135-
return withDangerousMod(config, [
136-
'ios',
137-
async (config) => {
138-
const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
139-
const contents = fs.readFileSync(filePath, 'utf-8');
140-
141-
const mergedPodfileWithStrictMode = mergeContents({
142-
tag: 'AppsFlyer Strict Mode',
143-
src: contents,
144-
newSrc: `$RNAppsFlyerStrictMode=${shouldUseStrictMode}`,
145-
anchor: 'use_expo_modules!',
146-
offset: 0,
147-
comment: '#',
148-
});
149-
150-
if (!mergedPodfileWithStrictMode.didMerge) {
151-
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.");
152-
return config;
153-
}
154-
155-
fs.writeFileSync(filePath, mergedPodfileWithStrictMode.contents);
156-
157-
return config;
158-
},
159-
]);
135+
return withDangerousMod(config, [
136+
'ios',
137+
async (config) => {
138+
const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
139+
const contents = fs.readFileSync(filePath, 'utf-8');
140+
141+
const mergedPodfileWithStrictMode = mergeContents({
142+
tag: 'AppsFlyer Strict Mode',
143+
src: contents,
144+
newSrc: `$RNAppsFlyerStrictMode=${shouldUseStrictMode}`,
145+
anchor: 'use_expo_modules!',
146+
offset: 0,
147+
comment: '#',
148+
});
149+
150+
if (!mergedPodfileWithStrictMode.didMerge) {
151+
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.");
152+
return config;
153+
}
154+
155+
fs.writeFileSync(filePath, mergedPodfileWithStrictMode.contents);
156+
157+
return config;
158+
},
159+
]);
160160
}
161161

162162
module.exports = function withAppsFlyerIos(config, shouldUseStrictMode) {
163-
config = withPodfile(config, shouldUseStrictMode);
164-
config = withIosBridgingHeader(config);
165-
config = withAppsFlyerAppDelegate(config);
166-
return config;
163+
config = withPodfile(config, shouldUseStrictMode);
164+
config = withIosBridgingHeader(config);
165+
config = withAppsFlyerAppDelegate(config);
166+
return config;
167167
};

0 commit comments

Comments
 (0)