🌎
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
1
BugBattle.startNetworkRecording();
Copied!
1
[BugBattle startNetworkRecording];
Copied!
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
1
BugBattle.startNetworkRecording(for: sessionConfiguration)
Copied!
1
[BugBattle startNetworkRecordingForSessionConfiguration: sessionConfiguration];
Copied!

AFNetworking

To enable network logging for AFNetworking, create and use the following class.
1
// BBAFURLSessionManager.h
2
#import <AFNetworking/AFNetworking.h>
3
​
4
@interface BBAFURLSessionManager : AFHTTPSessionManager
5
​
6
@end
7
​
8
// BBAFURLSessionManager.m
9
#import "BBAFURLSessionManager.h"
10
#import <BugBattle/BugBattle.h>
11
​
12
@implementation BBAFURLSessionManager
13
​
14
- (instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration {
15
[BugBattle startNetworkRecordingForSessionConfiguration: configuration];
16
17
return [super initWithSessionConfiguration:configuration];
18
}
19
​
20
@end
Copied!
Example usage for the BBAFURLSessionManager.
1
// Use the BBAFURLSessionManager for all further requests
2
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
3
BBAFURLSessionManager *manager = [[BBAFURLSessionManager alloc] initWithSessionConfiguration: configuration];
4
​
5
[manager GET: @"https://www.example.org/get" parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
6
NSLog(@"JSON: %@", responseObject);
7
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
8
NSLog(@"Error: %@", error);
9
}];
Copied!

Alamofire

To enable network logging for Alamofire, create and use the following class.
1
import Alamofire
2
import BugBattle
3
​
4
class BBSessionManager: Alamofire.Session {
5
static let sharedManager: BBSessionManager = {
6
let configuration = URLSessionConfiguration.default
7
BugBattle.startNetworkRecording(for: configuration)
8
let manager = BBSessionManager(configuration: configuration)
9
return manager
10
}()
11
}
Copied!
Example usage for the BBSessionManager.
1
BBSessionManager.sharedManager.request("https://www.sample.org/get").response { response in
2
debugPrint(response)
3
}
Copied!

​

Last modified 3mo ago