@@ -73,13 +73,22 @@ function reportCurrentViewForAndroid(screenName: string | null) {
73
73
}
74
74
75
75
function _logFlags() {
76
- console.log(
77
- `Andrew: init -> {
76
+ if (Platform.OS === 'android') {
77
+ console.log(
78
+ `Andrew: APM Flags -> {
78
79
isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled},
79
80
hasAPMNetworkPlugin: ${hasAPMNetworkPlugin},
80
81
shouldEnableNativeInterception: ${shouldEnableNativeInterception}
81
82
}`,
82
- );
83
+ );
84
+ } else {
85
+ console.log(
86
+ `Andrew: APM Flags -> {
87
+ isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled},
88
+ shouldEnableNativeInterception: ${shouldEnableNativeInterception}
89
+ }`,
90
+ );
91
+ }
83
92
}
84
93
85
94
/**
@@ -101,19 +110,19 @@ export const init = async (config: InstabugConfig) => {
101
110
// Add app state listener to handle background/foreground transitions
102
111
addAppStateListener(async (nextAppState) => handleAppStateChange(nextAppState, config));
103
112
113
+ // Perform platform-specific checks and update interception mode
114
+ handleNetworkInterceptionMode(config);
115
+
116
+ // Log the current APM network flags and initialize Instabug
117
+ _logFlags();
118
+
104
119
//Set APM networking flags for the first time
105
120
setApmNetworkFlagsIfChanged({
106
121
isNativeInterceptionFeatureEnabled: isNativeInterceptionFeatureEnabled,
107
122
hasAPMNetworkPlugin: hasAPMNetworkPlugin,
108
123
shouldEnableNativeInterception: shouldEnableNativeInterception,
109
124
});
110
125
111
- // Perform platform-specific checks and update interception mode
112
- handleNetworkInterceptionMode(config);
113
-
114
- // Log the current APM network flags and initialize Instabug
115
- _logFlags();
116
-
117
126
// call Instabug native init method
118
127
initializeNativeInstabug(config);
119
128
@@ -140,16 +149,20 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab
140
149
// Checks if the app has come to the foreground
141
150
if (['inactive', 'background'].includes(_currentAppState) && nextAppState === 'active') {
142
151
// Update the APM network flags
143
- const updatedFlags = await fetchApmNetworkFlags();
144
- const isUpdated = setApmNetworkFlagsIfChanged(updatedFlags);
152
+ const isUpdated = await fetchApmNetworkFlags();
145
153
146
154
if (isUpdated) {
155
+ console.log('Andrew: App has come to the foreground!');
147
156
console.log('Andrew: APM network flags updated.');
148
157
handleNetworkInterceptionMode(config);
149
- initializeNativeInstabug(config);
158
+ handleIOSNativeInterception(config);
159
+ _logFlags();
160
+ setApmNetworkFlagsIfChanged({
161
+ isNativeInterceptionFeatureEnabled,
162
+ hasAPMNetworkPlugin,
163
+ shouldEnableNativeInterception,
164
+ });
150
165
}
151
- _logFlags();
152
- console.log('Andrew: App has come to the foreground!');
153
166
}
154
167
155
168
_currentAppState = nextAppState;
@@ -160,16 +173,25 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab
160
173
* Fetches the current APM network flags.
161
174
*/
162
175
const fetchApmNetworkFlags = async () => {
163
- isNativeInterceptionFeatureEnabled = await NativeNetworkLogger.isNativeInterceptionEnabled();
176
+ let isUpdated = false;
177
+ const newNativeInterceptionFeatureEnabled =
178
+ await NativeNetworkLogger.isNativeInterceptionEnabled();
179
+ if (isNativeInterceptionFeatureEnabled !== newNativeInterceptionFeatureEnabled) {
180
+ isNativeInterceptionFeatureEnabled = newNativeInterceptionFeatureEnabled;
181
+ isUpdated = true;
182
+ }
164
183
if (Platform.OS === 'android') {
165
- hasAPMNetworkPlugin = await NativeNetworkLogger.hasAPMNetworkPlugin();
184
+ const newHasAPMNetworkPlugin = await NativeNetworkLogger.hasAPMNetworkPlugin();
185
+ if (hasAPMNetworkPlugin !== newHasAPMNetworkPlugin) {
186
+ hasAPMNetworkPlugin = newHasAPMNetworkPlugin;
187
+ isUpdated = true;
188
+ }
166
189
}
167
190
168
- return {
169
- isNativeInterceptionFeatureEnabled,
170
- hasAPMNetworkPlugin,
171
- shouldEnableNativeInterception,
172
- };
191
+ console.log(
192
+ `Andrew: fetchApmNetworkFlags {isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled}, hasAPMNetworkPlugin: ${hasAPMNetworkPlugin}}`,
193
+ );
194
+ return isUpdated;
173
195
};
174
196
175
197
/**
@@ -195,7 +217,8 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
195
217
};
196
218
197
219
/**
198
- * Handles the JS interception logic for Android.
220
+ * Handles the network interception logic for Android if the user set
221
+ * network interception mode with [NetworkInterceptionMode.javascript].
199
222
*/
200
223
function handleAndroidJSInterception() {
201
224
if (isNativeInterceptionFeatureEnabled && hasAPMNetworkPlugin) {
@@ -207,7 +230,8 @@ function handleAndroidJSInterception() {
207
230
}
208
231
209
232
/**
210
- * Handles the native interception logic for Android.
233
+ * Handles the network interception logic for Android if the user set
234
+ * network interception mode with [NetworkInterceptionMode.native].
211
235
*/
212
236
function handleAndroidNativeInterception() {
213
237
if (isNativeInterceptionFeatureEnabled) {
@@ -231,7 +255,30 @@ function handleAndroidNativeInterception() {
231
255
}
232
256
233
257
/**
234
- * Handles the interception mode logic for Android.
258
+ * Control either to enable or disable the native interception logic for iOS.
259
+ */
260
+ function handleIOSNativeInterception(config: InstabugConfig) {
261
+ if (Platform.OS === 'ios') {
262
+ console.log(
263
+ `Andrew: handleIOSNativeInterception(${
264
+ shouldEnableNativeInterception &&
265
+ config.networkInterceptionMode === NetworkInterceptionMode.native
266
+ })`,
267
+ );
268
+
269
+ if (
270
+ shouldEnableNativeInterception &&
271
+ config.networkInterceptionMode === NetworkInterceptionMode.native
272
+ ) {
273
+ NativeNetworkLogger.forceStartNetworkLoggingIOS(); // Enable native iOS automatic network logging.
274
+ } else {
275
+ NativeNetworkLogger.forceStopNetworkLoggingIOS(); // Disable native iOS automatic network logging.
276
+ }
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Handles the network interception mode logic for Android.
235
282
* By deciding which interception mode should be enabled (Native or JavaScript).
236
283
*/
237
284
const handleInterceptionModeForAndroid = (config: InstabugConfig) => {
0 commit comments