|
1 | | -const { withDangerousMod, withAppDelegate, WarningAggregator } = require('@expo/config-plugins'); |
| 1 | +const { withAppDelegate, withDangerousMod, withXcodeProject, WarningAggregator } = require('@expo/config-plugins'); |
2 | 2 | const { mergeContents } = require('@expo/config-plugins/build/utils/generateCode'); |
3 | 3 | const { getAppDelegate } = require('@expo/config-plugins/build/ios/Paths'); |
4 | 4 | const fs = require('fs'); |
5 | 5 | const path = require('path'); |
6 | 6 |
|
| 7 | +function getBridgingHeaderPathFromXcode(project) { |
| 8 | + const buildConfigs = project.pbxXCBuildConfigurationSection(); |
| 9 | + |
| 10 | + for (const key in buildConfigs) { |
| 11 | + const config = buildConfigs[key]; |
| 12 | + if ( |
| 13 | + typeof config === 'object' && |
| 14 | + config.buildSettings && |
| 15 | + config.buildSettings['SWIFT_OBJC_BRIDGING_HEADER'] |
| 16 | + ) { |
| 17 | + const bridgingHeaderPath = config.buildSettings[ |
| 18 | + 'SWIFT_OBJC_BRIDGING_HEADER' |
| 19 | + ].replace(/"/g, ''); |
| 20 | + |
| 21 | + return bridgingHeaderPath; |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + return null; |
| 26 | +} |
| 27 | + |
7 | 28 | function modifyObjcAppDelegate(appDelegate) { |
8 | 29 | const RNAPPSFLYER_IMPORT = `#import <RNAppsFlyer.h>\n`; |
9 | 30 | const RNAPPSFLYER_CONTINUE_USER_ACTIVITY_IDENTIFIER = `- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {`; |
@@ -88,47 +109,48 @@ function withAppsFlyerAppDelegate(config) { |
88 | 109 | }); |
89 | 110 | } |
90 | 111 |
|
91 | | -function withIosBridgingHeader(config) { |
92 | | - return withDangerousMod(config, [ |
93 | | - 'ios', |
94 | | - async (config) => { |
95 | | - const projectRoot = config.modRequest.projectRoot; |
96 | | - const projectName = config.modRequest.projectName || config.name; |
97 | | - const appDelegate = getAppDelegate(projectRoot); |
98 | | - |
99 | | - if (appDelegate.language === 'swift') { |
100 | | - const bridgingHeaderPath = path.join( |
101 | | - config.modRequest.platformProjectRoot, |
102 | | - config.name, |
103 | | - `${projectName}-Bridging-Header.h`, |
104 | | - ); |
105 | | - |
106 | | - if (fs.existsSync(bridgingHeaderPath)) { |
107 | | - let content = fs.readFileSync(bridgingHeaderPath, 'utf8'); |
108 | | - const appsFlyerImport = '#import <RNAppsFlyer.h>'; |
109 | | - |
110 | | - if (!content.includes(appsFlyerImport)) { |
111 | | - content += `${appsFlyerImport}\n`; |
112 | | - fs.writeFileSync(bridgingHeaderPath, content); |
113 | | - } |
114 | | - } else { |
115 | | - WarningAggregator.addWarningIOS( |
116 | | - 'withIosBridgingHeader', |
| 112 | +const withIosBridgingHeader = (config) => { |
| 113 | + return withXcodeProject(config, (action) => { |
| 114 | + const projectRoot = action.modRequest.projectRoot; |
| 115 | + const appDelegate = getAppDelegate(projectRoot); |
| 116 | + |
| 117 | + if (appDelegate.language === 'swift') { |
| 118 | + const bridgingHeaderPath = getBridgingHeaderPathFromXcode( |
| 119 | + action.modResults, |
| 120 | + ); |
| 121 | + |
| 122 | + const bridgingHeaderFilePath = path.join( |
| 123 | + action.modRequest.platformProjectRoot, |
| 124 | + bridgingHeaderPath, |
| 125 | + ); |
| 126 | + |
| 127 | + if (fs.existsSync(bridgingHeaderFilePath)) { |
| 128 | + let content = fs.readFileSync(bridgingHeaderFilePath, 'utf8'); |
| 129 | + const appsFlyerImport = '#import <RNAppsFlyer.h>'; |
| 130 | + |
| 131 | + if (!content.includes(appsFlyerImport)) { |
| 132 | + content += `${appsFlyerImport}\n`; |
| 133 | + fs.writeFileSync(bridgingHeaderFilePath, content); |
| 134 | + } |
| 135 | + |
| 136 | + return action; |
| 137 | + } |
| 138 | + |
| 139 | + WarningAggregator.addWarningIOS( |
| 140 | + 'withIosBridgingHeader', |
117 | 141 | ` |
118 | 142 | Failed to detect ${bridgingHeaderPath} file. Please add AppsFlyer integration manually: |
119 | 143 | #import <RNAppsFlyer.h> |
120 | 144 |
|
121 | 145 | Supported format: Expo SDK default template |
122 | 146 | ` |
123 | | - ); |
124 | | - } |
| 147 | + ); |
125 | 148 |
|
126 | | - return config; |
127 | | - } |
| 149 | + return action; |
| 150 | + } |
128 | 151 |
|
129 | | - return config; |
130 | | - }, |
131 | | - ]); |
| 152 | + return action; |
| 153 | + }); |
132 | 154 | }; |
133 | 155 |
|
134 | 156 | function withPodfile(config, shouldUseStrictMode) { |
|
0 commit comments