Skip to content

rob2468/HttpServerDebug

Repository files navigation

HttpServerDebug (HSD)

Build Status License

中文文档

Overview

HSD offers debug utilities (exploring file system, inspecting database, etc.) with the help of http server. HSD will start http server in your device, and you can connect to the server through user agents in the local area network.

Requirements:

  • iOS 8.0 or later (armv7, armv7s or arm64)

Demo screenshot

index

file explorer

view debug

Integration

Packaging way

In the root directory, there is the "archive.sh" script. cd to the root directory, then bash archive.sh. This script will generate files in the "output" folder in the same directory. The "output" folder contains three kinds of files, headers, library and bundle. These are all files that needed.

HttpServerDebug utilizes some third party libraries, e.g. FMDB. "archive.sh" script will compile all source files and integrate all contents in one static library, libHttpServerDebug.a. But sometimes you may want to exclude some third party libraries if your project has already import. You can update "archive.sh". For example, if you want to remove FMDB, set FMDB_INCLUDE=0.

# Dependencies onfiguration
FMDB_INCLUDE=0            # exclude FMDB

Source code way

You can copy source code files to your project directly. Classes/ and Resources/ in the root directory contains HSD codes and resources. ThirdParties/ contains dependent libraries, and you should copy as needed.

CocoaPods way

Add following statements in your Podfile.

pod 'HttpServerDebug', '~> 0.2'

Access HSD

As HSD is started as a http server in your device, you can access it just like browsing normal websites in your favorite web browser. HSD also provides some useful server apis, you can get these apis' description from Documents/ Directory. There are several ways you can get the HSD host name.

HSD Control Pannel

HSD provides a control pannel, where you can make HSD running in the way that you want.

control pannel

Public Host Name Resolving Interface

HSD also makes the host name resolving interface, +[HSDManager resolveHostName:] used in the control pannel, public. You can call this method and display host name in your custom views.

Browse And Lookup

If you start up HSD silently, the following method is another way to access HSD.

When HSD is started, the builtin bonjour broadcasting of _http._tcp type service is also published. You can browse for instances of service type _http._tcp in domain local.. When you get the instance name, you can lookup the target hostname to contact. In the following example, we use the dns-sd tool to browse and lookup the target hostname.

chenjundeMacBook-Pro:~ chenjun$ dns-sd -B _http
Browsing for _http._tcp
DATE: ---Wed 04 Apr 2018---
10:10:14.738  ...STARTING...
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name
10:10:14.738  Add        2  13 local.               _http._tcp.          陈军的iPhone 7

chenjundeMacBook-Pro:~ chenjun$ dns-sd -L "陈军的iPhone 7" _http
Lookup 陈军的iPhone 7._http._tcp.local
DATE: ---Wed 04 Apr 2018---
10:10:45.715  ...STARTING...
10:10:45.879  陈军的iPhone\0327._http._tcp.local. can be reached at chenjundeiPhone-7.local.:5555 (interface 13)

Manually

AS HSD runs on a http server, with your device's ip address and http server's listening port number, you can construct the complete URL.

FAQ

  1. Why does Xcode produce dupliate symbol errors. ("duplicate symbol xxx in:/xxx/libHttpServerDebug.a(xxx.o) /xxx/xxx(xxx.o) ld: xxx duplicate symbols for architecture xxx")

When your project contains some same classes, the linker produces these errors.

As HttpServerDebug imports some third party libraries, if your project has already import one, then exclude it in the "archive.sh" as described above.

  1. How to link HttpServerDebug in specific configuration?

For example, import HttpServerDebug only in Debug configuration.

  • Search HttpServerDebug Headers in Debug configuration.

    • "Build Settings -> Header Search Paths", add header searching paths for Debug configuration.
  • Link Binary With Libraries in Debug configuration.

    • "Build Settings -> Other Link Flags", add "-lHttpServerDebug" for Debug configuration.

    • "Build Settings -> Library Search Paths", add libHttpServerDebug.a searching path for Debug configuration.

  • Copy Bundle Resources in Debug configuration.

    • Add copy bundle resources script in "Build Phases -> Run Script".
if [ "${CONFIGURATION}" == "Debug" ]; then
  cp -r "${PROJECT_DIR}/HttpServerDebug.bundle" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app"
fi

Acknowledgments

CocoaHTTPServer, FLEX, Custom-Context-Menu, ZipArchive, GCDWebServer