Inspect network traffic in your mobile app. See outgoing requests and incoming responses, their timing, headers, response codes and most imporantly body.
First you need an desktop application to be able to connect to your device or emulator and see requests coupled together with their responses.
build.gradle
debugImplementation "dev.nosytools:inspect:1.2.0"
LoggingInterceptor
when configuring OkHttpClient
. Make sure it is not included for release builds.
import dev.nosytools.inspect.LoggingInterceptor;
// (...)
OkHttpClient.Builder()
.addInterceptor(LoggingInterceptor())
.build()
Nosy Inspect is provided as a Swift Package for iOS.
https://github.com/kkosobudzki/nosy-ios
NosyInspect
in your AppDelegate.m
file.
Make sure it is imported only in debug mode. Last but not least,
initialize it.
#if DEBUG
@import NosyInspect;
#endif
// (...)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// (...)
#if DEBUG
[NosyInspect inspect];
#endif
// (...)
}
To use Nosy Inspect in React Native applications, following changes in native parts requried.
android/app/build.gradle
debugImplementation "dev.nosytools:inspect:1.2.0"
HttpClientFactory.kt
for debug variant to be sure it
is not included for release builds. Let's add the file into android/app/src/debug/java/com/yourawesomeproject
directory.
package com.yourawesomeproject
import com.facebook.react.modules.network.OkHttpClientFactory
import com.facebook.react.modules.network.ReactCookieJarContainer
import dev.nosytools.inspect.LoggingInterceptor
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit
class HttpClientFactory : OkHttpClientFactory {
override fun createNewNetworkModuleClient(): OkHttpClient =
OkHttpClient.Builder()
.connectTimeout(0, TimeUnit.MILLISECONDS)
.readTimeout(0, TimeUnit.MILLISECONDS)
.writeTimeout(0, TimeUnit.MILLISECONDS)
.cookieJar(ReactCookieJarContainer())
.addInterceptor(LoggingInterceptor())
.build()
}
Timeouts are set to 0
which is infinite. It is not
required by Nosy Inspect but let you find and log long haning requests
without them being killed.
HttpClientFactory.kt
for release variant. Let's add
the file into android/app/src/release/java/com/yourawesomeproject
directory.
package com.yourawesomeproject
import com.facebook.react.modules.network.OkHttpClientFactory
import com.facebook.react.modules.network.ReactCookieJarContainer
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit
class HttpClientFactory : OkHttpClientFactory {
override fun createNewNetworkModuleClient(): OkHttpClient =
OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(1, TimeUnit.MINUTES)
.cookieJar(ReactCookieJarContainer())
.build()
}
Feel free to modify timeouts to match your requirements. One minute seems a way too long for a production ready app.
Use HttpClientFactory
in onCreate()
method
inside application file (android/app/src/main/java/com/yourawesomeproject/MainApplication.java
).
package com.yourawesomeproject
// (...)
import com.facebook.react.modules.network.OkHttpClientProvider;
// (...)
@Override
public void onCreate() {
super.onCreate();
// (...)
OkHttpClientProvider.setOkHttpClientFactory(new HttpClientFactory());
}
Nosy Inspect is provided as a Swift Package for iOS.
https://github.com/kkosobudzki/nosy-ios
NosyInspect
in your AppDelegate.m
file.
Make sure it is imported only in debug mode. Last but not least,
initialize it.
#if DEBUG
@import NosyInspect;
#endif
// (...)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// (...)
#if DEBUG
[NosyInspect inspect];
#endif
// (...)
}