Light mode | Dark mode |
---|---|
![]() |
![]() |
To run the example project, clone the repo, and run pod install
from the Example directory first.
NetworkAnalyzer is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'NetworkAnalyzer'
Create your NADataSource
class MyNADataSource: NADataSource {
private let cache = Cache.shared
init() {
inserEvent()
}
func logs() async throws -> [NetworkAnalyzerData] {
cache.get(forKey: .networkEvents) ?? []
}
func clear() async throws {
cache.remove(forKey: .networkEvents)
}
private func inserEvent() {
let baseUrl = "https://api.something.com"
let path = "/some/path"
let headers = "\"Authorization\": \"Bearer 31cah32....\""
let query = "some=data&something=anotherData"
let requestBody = "{\"firstName\": \"Network\" }"
let response = "{\"lasName\": \"Analyzer\" }"
let event = NetworkAnalyzerData(baseUrl: baseUrl,
method: "GET",
path: path,
absoluteUrl: baseUrl + path,
headers: headers,
query: query,
requestBody: requestBody,
statusCode: 200,
response: response,
date: Date())
/**
⚠️ Please use a security storage, UserDefaults isn't a secure storage
*/
let events: [NetworkAnalyzerData] = Cache.shared.get(forKey: .networkEvents) ?? []
cache.set([event] + events , forKey: .networkEvents)
}
}
Show network area example
let controller = NetworkAnalyzer.shared.makeNetworkAnalyzerViewController(provider: MyNADataSource())
let navigation = UINavigationController(rootViewController: controller)
present(navigation, animated: true, completion: nil)
daflecardoso, [email protected]
NetworkAnalyzer is available under the MIT license. See the LICENSE file for more info.