- Notifications
You must be signed in to change notification settings - Fork18
Network Monitor SDK for iOS
License
Farfetch/network-monitor-ios
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
FNMNetworkMonitor is a swift iOS networking framework that can be used to monitor the network of an iOS app.It makesdebugging the network easy, allowing you to pinpoint the root cause of network related problems in your app and share those requests via email.it can alsomock network requests, making it much easier to use incomplete APIs or model specific states for unit testing.
Supports Swift 5 and is bridged for Obj-C compatibility.
Preview:
- Add
pod 'FNMNetworkMonitor'to yourPodfile
- AddFNMNetworkMonitor to your Apps' Swift Packages in Xcode
- Monitoring URLSession.shared:
FNMNetworkMonitor.registerToLoadingSystem()FNMNetworkMonitor.shared.startMonitoring()
- Monitoring custom URLSessions by supplying the FNMMonitor URL Protocol:
letsessionConfig=URLSessionConfiguration.ephemeralsessionConfig.protocolClasses=FNMNetworkMonitor.normalizedURLProtocols()self.customSession=URLSession(configuration: sessionConfig)FNMNetworkMonitor.shared.startMonitoring()
- You can also take advantage of swizzling the URLSessionConfiguration creation to configure the URL Protocol to all sessions, allowing to monitor 3rd party SDKs too.
letrequest=FNMProfileRequest(urlPattern:.dynamicPattern(expression:"*farfetch.*robots"))letprofiles=[FNMProfile(request: request, responses:[request.response(statusCode:200, headers:["Content-Type":"application/json"], responseHolder:.keyValue(value:["FieldA":1]) delay:0.25)])]FNMNetworkMonitor.shared.configure(profiles: profiles)FNMNetworkMonitor.shared.startMonitoring()
You can also ignore domains using:
FNMNetworkMonitor.shared.configure(ignoredDomains:["somedomain.com"])
This won't record nor intercept requests for this domain.
You can also assign priority values to each profile, so that in case of a tie, the profile with the highest priority will be used.Priority is a UInt, being 0 the highest priority and UInt.max the lowest.
letrequest=FNMProfileRequest(urlPattern:.dynamicPattern(expression:"*farfetch.*robots"))letprofiles=[FNMProfile(request: request, responses:[request.response(statusCode:200)], priority:123)]
Make sure to follow steps 1, 2 or 3, depending on the URLSession that runs that particular request.
A debug UI exists that can be used for easy inspection and export of the network:
FNMNetworkMonitor.shared.showDebugListingViewController(presentingNavigationController:self.navigationController)
Generally, the shake gesture is a great way to show/hide the debug view.
Also, different log levels can be applied to see how the requests are navigating through the monitor:
FNMNetworkMonitor.shared.logScope=[.export,.profile,.urlProtocol]
Finally, you can turn on the passive export and the requests will be exported to a json file inside a folder found the Documents application folder.
FNMNetworkMonitor.shared.passiveExportPreference=FNMRecordExporterPreference.on(setting:.unlimited)
If you want to allocate less memory while using network monitor, you can disable media paylod recording:
FNMNetworkMonitor.shared.recordMediaPayload(false)
The project contains a sample app where you can test the tool. You can run the Sample Target Scheme inNetworkMonitor.xcworkspace to see a working example of the framework.
Read theContributing guidelines
By sending us your contributions, you are agreeing that your contribution is made subject to the terms of ourContributor Ownership Statement
List ofMaintainers
The FNMNetworkMonitor is released under theMIT license. See the LICENSE file for more details.
About
Network Monitor SDK for iOS
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.
