Skip to content

Latest commit

 

History

History
290 lines (230 loc) · 12.1 KB

setup.md

File metadata and controls

290 lines (230 loc) · 12.1 KB

Setting up Necto in an app

Necto's SDK is a debug tool that compiles into your app. This page covers integrating the SDK and excluding its calls from production builds, for iOS and Android. Install the Mac app separately using install.md.

Use Necto only with trusted apps and runtime environments, including development devices and networks.

iOS

The SDK connection has no peer authentication or TLS: USB and loopback do not prevent other apps on the device or programs on the Mac from connecting. Do not expose or forward its ports to untrusted networks.

Wiring it up

Add https://github.com/toss/necto.git in Xcode's Package Dependencies. Select NectoSDK and only the plugin products you need. The example below also uses NectoEventsPlugin, NectoProcessMetricPlugin, NectoURLSessionCapturePlugin and NectoUIControlPlugin. Automatic capture and UI Control use private APIs; omit those two products in apps that prohibit private APIs.

import NectoEventsPlugin
import NectoUIControlPlugin
import NectoProcessMetricPlugin
import NectoSDK
import NectoURLSessionCapturePlugin

let events = NectoEventsPlugin()
NectoSDK.register(URLSessionNetworkPlugin())   // network, captured for you
NectoSDK.register(events)
NectoSDK.register(ProcessPerformancePlugin())  // six process metrics while observed
NectoSDK.register(NectoUIControlPlugin())
NectoSDK.start()
events.report(NectoEvent(level: .info, tag: "App", message: "App started"))

Register only the plugins you need. Adding the package does not register plugins, start a listener or enable capture. Each selected plugin carries only its own code and panel resources, plus its declared dependencies. Your own plugins register the same way; their panels appear in Necto when the app connects. See the device plugin tutorial for a complete implementation.

Choosing products

Product / import Purpose Private APIs
NectoSDK Connection and plugin registration No
NectoNetworkPlugin Report requests from your own networking hooks No
NectoEventsPlugin Application events No
NectoFilesPlugin Files No
NectoPreferencesPlugin Preferences No
NectoPerformancePlugin Report performance readings No
NectoProcessMetricPlugin Automatic process metrics No
NectoUIControlPlugin UI inspection and interaction Yes
NectoURLSessionCapturePlugin Automatic URLSession recording Yes

Apps previously using only NectoSDK must explicitly add the products they use. Replace import NectoDefaultPlugins with imports for the individual plugins above. Rename NectoProcessMetrics and NectoURLSessionCapture imports to NectoProcessMetricPlugin and NectoURLSessionCapturePlugin. Registration methods and plugin type names are unchanged.

.product(name: "NectoSDK", package: "necto"),
.product(name: "NectoNetworkPlugin", package: "necto"),
.product(name: "NectoEventsPlugin", package: "necto")

Keeping it away from users

Do not run debugging tools in builds distributed to users.

The SDK does not restrict capture to a build configuration. The app decides where to include the products and when to register plugins and start the SDK, including internal Release builds.

The built-in UI Control provider synthesizes touches using private UIKit and IOHID entry points. Its Swift implementation lives in NectoUIControlPlugin and resolves selectors and C functions at runtime instead of linking Objective-C private method declarations. It supports positioned taps, 1–5 simultaneous fingers, 1–3 successive taps, swipes, and edge-back gestures. Native controls and text inputs are discovered through public UIKit properties. SwiftUI support additionally enables application accessibility through _AXSApplicationAccessibilitySetEnabled and routes each touch through _UIHitTestContext, _hitTestWithContext: and _setResponder:. These use the same runtime symbol resolver; there is no separate libAccessibility.dylib load or _accessibilityInit call. If these runtime entry points are missing, SwiftUI target discovery or touch delivery may be unavailable. Runtime lookup does not make these APIs public. Missing required touch entry points return OPERATION_UNAVAILABLE. OS changes can still break the implementation, and Swift cannot catch Objective-C exceptions.

Runtime lookup is not a guarantee of App Store Connect or TestFlight acceptance. Inspect the final app and embedded frameworks, and keep the debugging tool out of builds distributed to users.

Registering URLSessionNetworkPlugin starts network capture. Calling NectoSDK.start() lets you view the captured requests in the Necto app on your Mac.

Excluding calls does not remove the package. Swift Package Manager links a product in every build configuration, so the code and panel resources stay in a Release build even when every Necto call is under #if DEBUG.

To keep them out of the Release app, set Excluded Source File Names (EXCLUDED_SOURCE_FILE_NAMES) to Necto* for the Release configuration of the app target, and keep the imports and calls under #if DEBUG.

The pattern drops the package's object files and resource bundles from the app target. The package still compiles, and the pattern also excludes any file of your own whose name starts with Necto. How the setting applies can differ with the project setup, such as a plain Xcode project or Tuist, and with the Xcode version, so inspect the actual Release output:

ls YourApp.app | grep Necto
nm -U YourApp.app/YourApp | grep -ci necto

The first should print nothing and the second 0. If they do not, use a separate distribution target without Necto dependencies.

Where to start

Start with URLSessionNetworkPlugin and NectoEventsPlugin. Network requests appear as they happen. Keep the registered events instance in your app's debug logging code and call events.report(...) to send log entries, as in the example above. Add other plugins for the data you need to inspect.

Which requests are captured

Add NectoURLSessionCapturePlugin and register URLSessionNetworkPlugin() to automatically record HTTP(S) requests from URLSession.shared and sessions the app creates. Keep normal URLSession construction and request calls. No factory, wrapper or session protocol is required. Remove any old protocolClass registration; the compatibility protocol remains available but never intercepts a request.

Like PulseProxy, capture observes the original session through runtime hooks. It never reissues a request or replaces the application's configuration or delegates. Foundation and the app continue to handle credentials, cookies, authentication challenges and redirects. Use the public-API-only NectoNetworkPlugin for manual logging.

  • Capture works in both Debug and Release when installed. To exclude its private APIs, omit NectoURLSessionCapturePlugin from the app target dependencies.
  • Private Foundation classes and methods are involved. OS changes and other SDK hooks can affect capture. Presence and signature checks do not guarantee future compatibility.
  • Data, upload, download and streaming requests are recorded with bounded body previews. Application body streams are never consumed; streamed uploads may have no request preview.
  • WebSocket messages and background transfers running in another process are unsupported.
  • uninstall() stops recording. Hooks remain as pass-throughs instead of restoring old implementations over hooks installed by another SDK.

Reference implementations: PulseProxy and Atlantis Network.framework loader support.

Android

The Android SDK is a set of Gradle modules published through JitPack, for Android 8.0 (API 26) or later. It opens no network port: the app listens on a private Unix socket that only ADB reaches, accepts connections only from the shell and root users, and starts only in a debuggable app. Necto for Android covers the connection, its limits and how the plugins differ from iOS.

Adding the modules

Add JitPack to settings.gradle.kts, limited to Necto's group:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://jitpack.io")
            content { includeGroup("com.github.toss.necto") }
        }
    }
}

Add necto-android and only the plugin modules you need to the debug build. Pin every module to the same version, a release tag or a commit:

// app/build.gradle.kts
val nectoVersion = "COMMIT_OR_TAG"
dependencies {
    debugImplementation("com.github.toss.necto:necto-android:$nectoVersion")
    debugImplementation("com.github.toss.necto:necto-events-plugin:$nectoVersion")
}

Adding a module does not register a plugin or start a listener. Each module carries only its own code and panel, plus its declared dependencies.

Choosing modules

Module Purpose
necto-android Connection and plugin registration
necto-network-plugin Report requests from your own networking hooks
necto-events-plugin Application events
necto-files-plugin Files
necto-datastore-preferences-plugin DataStore Preferences
necto-performance-plugin Report performance readings
necto-process-metric-plugin Automatic process metrics
necto-ui-control-plugin UI inspection and interaction, for Views and Jetpack Compose
necto-okhttp-capture-plugin Automatic OkHttp recording
necto-ktor-capture-plugin Automatic Ktor client recording, on any engine

Keeping it out of release builds

Keep SDK references in the debug source set. A BuildConfig.DEBUG condition in src/main does not remove those references from release compilation.

// src/debug/kotlin/com/example/NectoSetup.kt
package com.example

import android.app.Application
import im.toss.necto.android.NectoAndroid
import im.toss.necto.plugins.NectoEventsPlugin

object NectoSetup {
    fun start(app: Application) {
        NectoAndroid.start(app, listOf(NectoEventsPlugin()))
    }
}
// src/release/kotlin/com/example/NectoSetup.kt
package com.example

import android.app.Application

object NectoSetup {
    fun start(app: Application) = Unit
}

Call NectoSetup.start(this) from the app's Application.onCreate. Release builds compile without any Necto dependency. Add a matching setup for other build types as needed.

Capturing OkHttp requests

Add necto-okhttp-capture-plugin to the debug dependencies and wire the same instance to the bridge and the app's client:

val network = OkHttpNetworkPlugin()
NectoAndroid.start(app, listOf(network))
val client = OkHttpClient.Builder()
    .addInterceptor(network.interceptor)
    .build()

Add the interceptor after any interceptor that checks a request body's type. For manual logging, use necto-network-plugin on its own.

Capturing Ktor requests

Add necto-ktor-capture-plugin to the debug dependencies and install the capture in the app's client, on any engine:

val network = KtorNetworkPlugin()
NectoAndroid.start(app, listOf(network))
val client = HttpClient(CIO) {
    install(network.capture)
}

It supports Ktor 3; Ktor 2 is not supported. Install the capture after a plugin that retries, such as HttpRequestRetry, so each attempt is its own record. On the OkHttp engine, use this or the OkHttp interceptor, not both, or every request is listed twice.

What connecting involves

  • iOS simulator: the Mac reaches the app over loopback.
  • iOS device: over the USB cable, through usbmuxd.
  • Android device or emulator: over ADB, to a private Unix socket in the app. A device connects over USB.
  • The iOS SDK listens on a local TCP port. If another simulator app holds it, the SDK looks for a free port within its port range. Necto does not use Bonjour or multicast.
  • Two apps, or the same app on two devices, connect side by side and are told apart in the sidebar and in necto-cli (--app, --device).