嗅探器 2.1.2

嗅探器 2.1.2

测试已测试
Lang语言 SwiftSwift
许可证 MIT
释放最后发布2020年12月
SPM支持SPM

Kofktu维护。



嗅探器 2.1.2

  • Kofktu

嗅探器

Build Status Swift Platform CocoaPods Carthage compatible SwiftPM compatible

  • 自动网络活动日志记录器
  • 截获任何 outgoing 请求和 incoming 响应,以便进行调试。

alt tag

要求

  • iOS 8.0+, macOS 10.9+, watchOS 2.0+, tvOS 9.0+
  • Swift 5.0
  • Swift 4.2 (1.7.0)
  • Swift 4.0 (1.5.0)
  • Swift 3.0 (1.0.6)

示例

要运行示例项目,请克隆仓库,然后首先从Example目录运行 pod install

安装

CocoaPods

Sniffer 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中

pod "Sniffer", '~> 2.0'

Carthage

适用于 iOS 8 及以上版本的项目,使用 Carthage

github "Kofktu/Sniffer"

使用方法

对于通过 'URLSession' 发出的任何请求

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

对于 URLSessionConfiguration

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

对于自定义反序列化器

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"])

如果要在您的应用程序中直接处理日志

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

如果您想忽略域

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

参考文献

贡献者

李丹 (kofktu), [email protected]

许可证

Sniffer遵循MIT许可证。更多详情请参阅LICENSE文件。