Skip to content

feat: implement iOS connectivity detection#12

Open
polw1 wants to merge 2 commits into
silvermine:masterfrom
polw1:feat/ios-connectivity
Open

feat: implement iOS connectivity detection#12
polw1 wants to merge 2 commits into
silvermine:masterfrom
polw1:feat/ios-connectivity

Conversation

@polw1
Copy link
Copy Markdown

@polw1 polw1 commented May 28, 2026

Adds iOS support for connection_status() using Apple’s NWPathMonitor.

Closes #9.

This wires a native iOS implementation into the existing plugin API while keeping the same ConnectionStatus response shape used by the cross-platform surface.

The iOS implementation is provided by ios/Sources/ConnectivityPlugin.swift and is backed by a long-lived NWPathMonitor. The monitor starts during plugin initialization, caches the latest observed NWPath, and connection_status() maps that cached state to:

  • connected
  • metered
  • constrained
  • connectionType

This avoids treating NWPathMonitor as a synchronous one-shot status getter and better matches Apple’s callback-driven API model.

On the Rust side, Connectivity is now platform-specific:

  • on iOS, it wraps a PluginHandle-backed native implementation
  • on non-iOS platforms, it keeps the existing lightweight local implementation

Because these types are materially different, the plugin state, extension trait return types, and initialization path branch under #[cfg(target_os = "ios")] and #[cfg(not(target_os = "ios"))].

I kept this split explicit in lib.rs to land the minimal iOS integration cleanly without introducing a broader abstraction layer in the same PR. A follow-up refactor can reduce the conditional boilerplate if needed.

Tested with:

  • npm run standards

Add an iOS platform implementation behind the connectivity plugin. The
Swift bridge runs an NWPathMonitor and resolves connected/metered/
constrained/connectionType from the cached NWPath, exposing it to Rust
through run_mobile_plugin. The Rust side gains an IosConnectivity handle
wrapper and a generic Connectivity<R> managed state.
Copy link
Copy Markdown
Contributor

@velocitysystems velocitysystems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @polw1. Please see comments below. Also, the Swift files use 2-space indentation; the Silvermine Swift standard is 3 spaces indentation.

Comment thread ios/Sources/ConnectivityPlugin.swift Outdated
Comment thread src/lib.rs Outdated
Comment thread ios/Sources/ConnectivityPlugin.swift Outdated
@polw1 polw1 requested a review from velocitysystems June 3, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement iOS support for connectivity detection

2 participants