🌎 Network logging

Bugbattle allows you to monitor all network requests for a better understanding of what's happening within your web-apps & websites. Enable network logging by calling the following method right after the initializing of the Bugbattle SDK.

Initialization

Swift
Objective-C
Swift
BugBattle.startNetworkRecording();
Objective-C
[BugBattle startNetworkRecording];

In certain circumstances you might need to pass an NSURLSessionConfiguration in order for BugBattle to be able to log the network requests.

Swift
Objective-C
Swift
BugBattle.startNetworkRecording(for: sessionConfiguration)
Objective-C
[BugBattle startNetworkRecordingForSessionConfiguration: sessionConfiguration];

AFNetworking

To enable network logging for AFNetworking, create and use the following class.

// BBAFURLSessionManager.h
#import <AFNetworking/AFNetworking.h>
​
@interface BBAFURLSessionManager : AFHTTPSessionManager
​
@end
​
// BBAFURLSessionManager.m
#import "BBAFURLSessionManager.h"
#import <BugBattle/BugBattle.h>
​
@implementation BBAFURLSessionManager
​
- (instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration {
[BugBattle startNetworkRecordingForSessionConfiguration: configuration];
return [super initWithSessionConfiguration:configuration];
}
​
@end

Example usage for the BBAFURLSessionManager.

// Use the BBAFURLSessionManager for all further requests
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
BBAFURLSessionManager *manager = [[BBAFURLSessionManager alloc] initWithSessionConfiguration: configuration];
​
[manager GET: @"https://www.example.org/get" parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"Error: %@", error);
}];

Alamofire

To enable network logging for Alamofire, create and use the following class.

import Alamofire
import BugBattle
​
class BBSessionManager: Alamofire.Session {
static let sharedManager: BBSessionManager = {
let configuration = URLSessionConfiguration.default
BugBattle.startNetworkRecording(for: configuration)
let manager = BBSessionManager(configuration: configuration)
return manager
}()
}

Example usage for the BBSessionManager.

BBSessionManager.sharedManager.request("https://www.sample.org/get").response { response in
debugPrint(response)
}

​