Code Monkey home page Code Monkey logo

sauron's Introduction

Sauron

"Buy Me A Coffee"

An iOS library to check and share network log easier, can be embedded into your iOS app easily

List Simulator Screenshot - iPhone 14 Pro - 2023-04-25 at 15 45 30 Simulator Screenshot - iPhone 14 Pro - 2023-04-25 at 15 45 33 Simulator Screenshot - iPhone 14 Pro - 2023-04-25 at 15 45 35 Simulator Screenshot - iPhone 14 Pro - 2023-04-25 at 15 45 38

Insprised by Reqres and Wormhole

Installation

Swift Package Manager

To integrate Sauron into your Xcode using Swift Package Manager, add it to the dependencies of Package.swift

dependencies: [
    .package(url: "https://github.com/volatilegg/Sauron.git", .upToNextMajor(from: "1.0"))
]

Cocoapods

To integrate Sauron into your Xcode using Cocoapod, add it to your Podfile

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '13.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Sauron', '~> 1.0.0'
end

Usage

1. Network configuration

Default network config

Using Reqres.defaultSessionConfiguration as URLSession.configuration

let url = URL(string: "https://pokeapi.co/api/v2/pokemon/108")!
let urlSessionConfig = Reqres.defaultSessionConfiguration(
  additionalHeaders: ["Content-Type":"application/json; charset=UTF-8"],
  additionalHeaders: 40,
  timeoutIntervalForResource: 40,
  requestCachePolicy: .useProtocolCachePolicy
)
let urlSession = URLSession(configuration: config, delegate: nil, delegateQueue: nil)

urlSession.dataTask(
  with: url,
  completionHandler: { (data, response, error) in
      // handling response callback
  }
)

Inject Reqres.defaultSessionConfiguration into Alamofire.Session(configuration:{{configuration}})

let urlSessionConfig = Reqres.defaultSessionConfiguration(
  additionalHeaders: ["Content-Type":"application/json; charset=UTF-8"],
  additionalHeaders: 40,
  timeoutIntervalForResource: 40,
  requestCachePolicy: .useProtocolCachePolicy
)

// Usage for Alamofire
let sessionManager = Alamofire.Session(configuration: urlSessionConfig)

// Usage for Moya
var provider = MoyaProvider<PokemonAPI>(
  endpointClosure: endpointClosure,
  session: sessionManager,
  plugins: []
)

provider.request(target) { result in
  // handling response callback
}

2. Configure log mode

Note default mode is disabled and should be the mode to use in prodution

Using this snippet to control the mode

// Display all network information
Sauron.shared.logMode = .enable

// Remove all network information
Sauron.shared.logMode = .disable

// Display network information without request's headers
Sauron.shared.logMode = .disableHeader

3. Configure log UI

SwiftUI

Open this view RequestListPresentView() to see the whole log UI

NavigationLink(destination: RequestListPresentView()) {
  Text("Open Log")
}

UIKit

Open this view RequestsListViewController to see the whole log UI

viewController.show(RequestsListViewController.makeViewController())

sauron's People

Contributors

volatilegg avatar

Stargazers

Dat Truong avatar Le Tu Binh avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.