Skip to content

Investigate on-device preview support (real iPhone/iPad) #20

@obj-p

Description

@obj-p

Explore whether PreviewsMCP can render previews on physical iOS devices, not just the simulator.

Core blocker

iOS prohibits dlopen of arbitrary unsigned code at runtime. The simulator doesn't have this restriction, which is why Xcode Previews only supports simulator too. Our entire preview pipeline depends on dlopen of compiled dylibs.

Approaches to investigate

1. Signed framework loading (most promising)
Can dlopen load a framework signed with the same team identity as the host app on a developer-mode device? If yes, the rest of the architecture (host app, touch injection, file communication) transfers directly. Compile preview as a .framework, sign with the dev cert, push to app's Frameworks/ directory.

2. JIT entitlement
Xcode's XCPreviewAgent uses a JIT executor to link .o files in-memory. The com.apple.security.cs.allow-jit entitlement enables this. Investigate whether a third-party app can use this entitlement on device (likely restricted to Apple-signed binaries).

3. Recompile + reinstall (slow but known-good)
Build the full app (host + preview) as a single binary each time. Sign and install via devicectl/ios-deploy. ~15-30s per iteration. No dlopen needed. Works on stock developer-mode devices.

4. Network rendering
Run compilation on Mac, render on Mac (simulator or in-process), stream frames to a companion app on device. Device is just a display. Different architecture but sidesteps all code signing issues.

What already works on device

  • Touch injection (Hammer approach is in-process, same on device)
  • Screenshots (devicectl or idb)
  • File communication (push to app sandbox via USB/network)
  • The host app pattern itself

Spike plan

  1. Create a minimal iOS app with developer signing
  2. At runtime, attempt to dlopen a .framework from the app's bundle that was NOT present at install time (pushed via devicectl after install)
  3. Test on a developer-mode device
  4. If it works: the path to on-device previews is clear
  5. If not: evaluate approach 3 (recompile+reinstall) for viability

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions