@@ -73,13 +73,22 @@ function reportCurrentViewForAndroid(screenName: string | null) {
7373}
7474
7575function _logFlags ( ) {
76- console . log (
77- `Andrew: init -> {
76+ if ( Platform . OS === 'android' ) {
77+ console . log (
78+ `Andrew: APM Flags -> {
7879 isNativeInterceptionFeatureEnabled: ${ isNativeInterceptionFeatureEnabled } ,
7980 hasAPMNetworkPlugin: ${ hasAPMNetworkPlugin } ,
8081 shouldEnableNativeInterception: ${ shouldEnableNativeInterception }
8182 }` ,
82- ) ;
83+ ) ;
84+ } else {
85+ console . log (
86+ `Andrew: APM Flags -> {
87+ isNativeInterceptionFeatureEnabled: ${ isNativeInterceptionFeatureEnabled } ,
88+ shouldEnableNativeInterception: ${ shouldEnableNativeInterception }
89+ }` ,
90+ ) ;
91+ }
8392}
8493
8594/**
@@ -101,19 +110,19 @@ export const init = async (config: InstabugConfig) => {
101110 // Add app state listener to handle background/foreground transitions
102111 addAppStateListener ( async ( nextAppState ) => handleAppStateChange ( nextAppState , config ) ) ;
103112
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+
104119 //Set APM networking flags for the first time
105120 setApmNetworkFlagsIfChanged ( {
106121 isNativeInterceptionFeatureEnabled : isNativeInterceptionFeatureEnabled ,
107122 hasAPMNetworkPlugin : hasAPMNetworkPlugin ,
108123 shouldEnableNativeInterception : shouldEnableNativeInterception ,
109124 } ) ;
110125
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-
117126 // call Instabug native init method
118127 initializeNativeInstabug ( config ) ;
119128
@@ -140,16 +149,20 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab
140149 // Checks if the app has come to the foreground
141150 if ( [ 'inactive' , 'background' ] . includes ( _currentAppState ) && nextAppState === 'active' ) {
142151 // Update the APM network flags
143- const updatedFlags = await fetchApmNetworkFlags ( ) ;
144- const isUpdated = setApmNetworkFlagsIfChanged ( updatedFlags ) ;
152+ const isUpdated = await fetchApmNetworkFlags ( ) ;
145153
146154 if ( isUpdated ) {
155+ console . log ( 'Andrew: App has come to the foreground!' ) ;
147156 console . log ( 'Andrew: APM network flags updated.' ) ;
148157 handleNetworkInterceptionMode ( config ) ;
149- initializeNativeInstabug ( config ) ;
158+ handleIOSNativeInterception ( config ) ;
159+ _logFlags ( ) ;
160+ setApmNetworkFlagsIfChanged ( {
161+ isNativeInterceptionFeatureEnabled,
162+ hasAPMNetworkPlugin,
163+ shouldEnableNativeInterception,
164+ } ) ;
150165 }
151- _logFlags ( ) ;
152- console . log ( 'Andrew: App has come to the foreground!' ) ;
153166 }
154167
155168 _currentAppState = nextAppState ;
@@ -160,16 +173,25 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab
160173 * Fetches the current APM network flags.
161174 */
162175const 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+ }
164183 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+ }
166189 }
167190
168- return {
169- isNativeInterceptionFeatureEnabled,
170- hasAPMNetworkPlugin,
171- shouldEnableNativeInterception,
172- } ;
191+ console . log (
192+ `Andrew: fetchApmNetworkFlags {isNativeInterceptionFeatureEnabled: ${ isNativeInterceptionFeatureEnabled } , hasAPMNetworkPlugin: ${ hasAPMNetworkPlugin } }` ,
193+ ) ;
194+ return isUpdated ;
173195} ;
174196
175197/**
@@ -194,7 +216,8 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
194216} ;
195217
196218/**
197- * Handles the JS interception logic for Android.
219+ * Handles the network interception logic for Android if the user set
220+ * network interception mode with [NetworkInterceptionMode.javascript].
198221 */
199222function handleAndroidJSInterception ( ) {
200223 if ( isNativeInterceptionFeatureEnabled && hasAPMNetworkPlugin ) {
@@ -206,7 +229,8 @@ function handleAndroidJSInterception() {
206229}
207230
208231/**
209- * Handles the native interception logic for Android.
232+ * Handles the network interception logic for Android if the user set
233+ * network interception mode with [NetworkInterceptionMode.native].
210234 */
211235function handleAndroidNativeInterception ( ) {
212236 if ( isNativeInterceptionFeatureEnabled ) {
@@ -230,7 +254,30 @@ function handleAndroidNativeInterception() {
230254}
231255
232256/**
233- * Handles the interception mode logic for Android.
257+ * Control either to enable or disable the native interception logic for iOS.
258+ */
259+ function handleIOSNativeInterception ( config : InstabugConfig ) {
260+ if ( Platform . OS === 'ios' ) {
261+ console . log (
262+ `Andrew: handleIOSNativeInterception(${
263+ shouldEnableNativeInterception &&
264+ config . networkInterceptionMode === NetworkInterceptionMode . native
265+ } )`,
266+ ) ;
267+
268+ if (
269+ shouldEnableNativeInterception &&
270+ config . networkInterceptionMode === NetworkInterceptionMode . native
271+ ) {
272+ NativeInstabug . setNetworkLoggingEnabled ( true ) ; // Enable native iOS automatic network logging.
273+ } else {
274+ NativeNetworkLogger . resetNetworkLogToDefaultStateIOS ( ) ; // Disable native iOS automatic network logging.
275+ }
276+ }
277+ }
278+
279+ /**
280+ * Handles the network interception mode logic for Android.
234281 * By deciding which interception mode should be enabled (Native or JavaScript).
235282 */
236283const handleInterceptionModeForAndroid = ( config : InstabugConfig ) => {
0 commit comments