Home

Awesome

Sniffer

Build Status Swift Platform CocoaPods Carthage compatible SwiftPM compatible

alt tag

Requirements

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

CocoaPods

Sniffer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Sniffer", '~> 2.0'

Carthage

For iOS 8+ projects with Carthage

github "Kofktu/Sniffer"

Usage

for any requests you make via 'URLSession'

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  Sniffer.register() // Register Sniffer to log all requests
  return true
}

for URLSessionConfiguration

let configuration = URLSessionConfiguration.default
Sniffer.enable(in: configuration)

for Custom Deserializer

public protocol BodyDeserializer {
    func deserialize(body: Data) -> String?
}

public final class CustomTextBodyDeserializer: BodyDeserializer {
    public func deserialize(body: Data) -> String? {
        // customization
        return String?
    }
}

Sniffer.register(deserializer: CustomTextBodyDeserializer(), for: ["text/plain"])

If you want to process the logs directly in your application

// Register the handler if you want the log to be handled directly by the application
Sniffer.onLogger = { (url, log) in
  print("\(url) : \(log)")
}

If you want to ignore domains

Sniffer.ignore(domains: ["github.com"])

References

Authors

Taeun Kim (kofktu), kofktu@gmail.com

License

Sniffer is available under the MIT license. See the LICENSE file for more info.