Skip to content

Parse Debugging Tools: Identify Client-Side Issues Faster

In order to build amazing apps you sometimes need to quickly debug issues. We recently launched the Parse Explorer tool to help with this process; it allows you to better investigate issues with your app’s API requests. However, even before diving into your API requests, you need to identify whether issues may be occurring on the client side instead. Today we're happy to introduce new Parse debugging tools for iOS and Android, which help you to identify client-side issues by surfacing requests and responses between the Parse SDK and Parse server.


Debugging tools for Android

For Android, we've created two tools: the log interceptor and the Stetho interceptor. Let's take a look at each one.

The log interceptor will log all requests and responses between the Parse SDK and server to Android logcat. It's easy to integrate with your app. After you add parseinterceptors-android dependency, all you need to do is add one line code before you initialize Parse in your Application#onCreate()

Parse.<i>addParseNetworkInterceptor</i>(<b>new </b>ParseLogInterceptor());
// Interceptor should be added before your initialize Parse
Parse.initialize(this);
....

Then, you can check the network information in Android logcat.

ParseLogInterceptor_ScreenShot

The second tool is the Parse Stetho interceptor. Stetho is an open source library which allows you to debug your app through the Chrome Developer tool. With the help of the Parse Stetho interceptor, you can easily integrate Parse and Stetho: After you add Stetho and parseinterceptors-android dependency, you just need to add a few lines of code before you initialize Parse in your Application#onCreate()

// The stetho initialization may change if you use different Stetho version
Stetho.initializeWithDefaults(this);

Parse.addParseNetworkInterceptor(new ParseStethoInterceptor());
// Interceptor should be added before your initialize Parse
Parse.initialize(this);
....

Once you complete the set-up, start your app, point your laptop browser to chrome://inspect and click the "Inspect" button to begin.

image


Debugging tools for iOS

On iOS we can take advantage of NSNotificationCenter to expose the NSURLRequest, NSURLResponse and the response body to you. In order to check them, you can add the following to your AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Set Parse log level to debug to request the debug notifications
    [Parse setLogLevel:PFLogLevelDebug];
    // Register observer and selector to receive the request we sent to server
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveWillSendURLRequestNotification:) name:PFNetworkWillSendURLRequestNotification object:nil];
    // Register observer and selector to receive the response we get from server
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveDidReceiveURLResponseNotification:) name:PFNetworkDidReceiveURLResponseNotification object:nil];
}

- (void)receiveWillSendURLRequestNotification:(NSNotification *) notification {
    // Use key to get the NSURLRequest from userInfo
    NSURLRequest *request = notification.userInfo[PFNetworkNotificationURLRequestUserInfoKey];
}

- (void)receiveDidReceiveURLResponseNotification:(NSNotification *) notification {
    // Use key to get the NSURLRequest from userInfo
    NSURLRequest *request = notification.userInfo[PFNetworkNotificationURLRequestUserInfoKey];
    // Use key to get the NSURLResponse from userInfo
    NSURLResponse *response = notification.userInfo[PFNetworkNotificationURLResponseUserInfoKey];
    NSString *responseBody = notification.userInfo[PFNetworkNotificationURLResponseBodyUserInfoKey];
}

Once you get the NSURLRequest, NSURLResponse and the response body, you can check them through the debugger or log them to console in Xcode.

Please check out our Github wiki page (Android, iOS) for more technical details about the network debugging tool. We’d love to hear your feedback.