|
1 | | -# NetworkInspector |
| 1 | +**NetworkInspector** |
2 | 2 |
|
3 | | -NetworkInspector is a lightweight in-app network inspection tool for iOS. |
4 | | -It intercepts `URLSession` traffic and provides a built-in UI to inspect |
5 | | -requests, responses, headers, status codes, timing, and payloads. |
| 3 | +NetworkInspector is a lightweight, in-app network inspection tool for iOS apps. |
| 4 | +It intercepts URLSession traffic and provides a built-in UI to inspect HTTP requests and responses in real time. |
6 | 5 |
|
7 | | -This tool is intended **strictly for DEBUG builds**. |
| 6 | +DEBUG builds only. Do not ship this tool in production. |
8 | 7 |
|
9 | | ---- |
| 8 | +**What It Does (Precisely)** : |
10 | 9 |
|
11 | | -## Features |
| 10 | +NetworkInspector works by registering a custom URLProtocol that observes network traffic initiated through URLSession. |
12 | 11 |
|
13 | | -- Intercepts all HTTP/HTTPS requests using `URLProtocol` |
14 | | -- Captures request & response headers, body, status code, and timing |
15 | | -- In-memory log storage with size limits |
16 | | -- Built-in inspector UI (list → detail → tabs) |
17 | | -- Pretty-printed JSON responses |
18 | | -- Floating overlay button (does not interfere with app UI) |
19 | | -- Works with UIKit and SwiftUI apps |
| 12 | +• Request method, URL, headers, and body |
| 13 | +• Response headers, status code, and body |
| 14 | +• Request timing and duration |
| 15 | +• Base URL grouping for easier filtering |
20 | 16 |
|
21 | | ---- |
| 17 | +All logs are stored in memory only (no disk persistence). |
22 | 18 |
|
23 | | -## Installation (Swift Package Manager) |
| 19 | +**Features:** |
24 | 20 |
|
25 | | -Add the package using Xcode: |
| 21 | +• Intercepts HTTP/HTTPS traffic using URLProtocol |
| 22 | +• Intercept all requests or only selected base URLs |
| 23 | +• Captures request and response headers and bodies |
| 24 | +• Captures status codes and timing information |
| 25 | +• In-memory log storage with size limits |
| 26 | +• Built-in inspector UI (List → Detail → Tabs) |
| 27 | +• Pretty-printed JSON responses |
| 28 | +• Share requests as cURL commands |
| 29 | +• Floating overlay button that does not block app interaction |
| 30 | +• Works with UIKit and SwiftUI |
26 | 31 |
|
27 | | -File → Add Packages → Paste repository URL |
| 32 | +**Installation (Swift Package Manager)** |
28 | 33 |
|
29 | | -## Usage |
| 34 | +• Open Xcode |
| 35 | +• Go to File → Add Packages |
| 36 | +• Paste https://github.com/Rev0212/iOS-NetworkInspector |
| 37 | +• Add the package to your app target |
30 | 38 |
|
31 | | -Enable the inspector in **DEBUG** builds only: |
| 39 | +**Usage** |
| 40 | +Enable the inspector in DEBUG builds to intercept all requests: |
32 | 41 |
|
33 | | -```swift |
34 | 42 | #if DEBUG |
35 | 43 | NetworkInspector.LeapInspector.enable() |
36 | 44 | NetworkInspector.LeapInspector.enableFloatingButton() |
37 | 45 | #endif |
38 | | -``` |
39 | 46 |
|
40 | | -A floating 📡 button will appear on screen. |
41 | | -Tap it to open the network inspector UI. |
| 47 | +To intercept only specific base URLs: |
42 | 48 |
|
43 | | -To capture only specific base URLs, pass one or more base addresses: |
44 | | - |
45 | | -```swift |
46 | 49 | #if DEBUG |
47 | | -NetworkInspector.enable( |
48 | | - baseURLs: [ |
49 | | - "https://mario-api.leapscholar.com", |
50 | | - "https://mario-ieltsbff.leapscholar.com" |
51 | | - ] |
52 | | -) |
| 50 | +NetworkInspector.enable(baseURLs: ["https://my-api.com", "https://my-base-api.com"]) |
53 | 51 | NetworkInspector.enableFloatingButton() |
54 | 52 | #endif |
55 | | -``` |
56 | 53 |
|
57 | | ---- |
58 | 54 |
|
59 | | -## API Tab |
| 55 | +**Inspector UI** |
| 56 | +• Floating button opens the inspector |
| 57 | +• Browse requests in a list view |
| 58 | +• Inspect headers, body, response, and timing |
| 59 | +• Share as cURL or delete logs |
| 60 | +• Overlay does not interfere with app UI |
| 61 | + |
| 62 | +**Important Notes** |
60 | 63 |
|
61 | | -The inspector UI includes an **APIs** tab that lists unique endpoints and the number |
62 | | -of calls for each. Tap an endpoint to view only the logs for that API. |
| 64 | +• DEBUG builds only |
| 65 | +• Works only with URLSession |
| 66 | +• Logs cleared on app restart |
| 67 | +• Intended strictly as a developer debugging tool |
0 commit comments