Skip to content

Fix iOS AppHang: dispatch getNetworkInfo off main thread#12

Merged
DaniloCharantola merged 2 commits into
mainfrom
fix/ios-main-thread-hang
Jun 11, 2026
Merged

Fix iOS AppHang: dispatch getNetworkInfo off main thread#12
DaniloCharantola merged 2 commits into
mainfrom
fix/ios-main-thread-hang

Conversation

@DaniloCharantola

Copy link
Copy Markdown
Contributor

Problem

On iOS, both CTTelephonyNetworkInfo() and SCNetworkReachabilityGetFlags perform synchronous XPC calls to system daemons under the hood. When invoked on the main thread, they block it until the system responds — which can take hundreds of milliseconds or longer under network or system load.

This was surfacing as AppHang PROD-APP-E37G: the Flutter method channel handler was calling getNetworkInfoResult() directly on the main thread, stalling the UI.

Fix

Wrap the getNetworkInfoResult() call in DispatchQueue.global(qos: .utility).async { ... } so the XPC-backed lookups happen off the main thread. The result callback is @escaping, so it is safe to call from a background queue.

Also fixed a long-standing typo: transport_subtype for WiFi connections was returning "unknwon" instead of "unknown".

Changes

File Description
ios/Classes/FlutterNetworkCapabilitiesPlugin.swift Dispatch getNetworkInfoResult() to a utility background queue; fix "unknwon""unknown" typo
pubspec.yaml Bump version 0.0.20.0.3
CHANGELOG.md Add entry for 0.0.3

@DaniloCharantola DaniloCharantola marked this pull request as ready for review June 11, 2026 13:57
Copilot AI review requested due to automatic review settings June 11, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses an iOS UI stall (AppHang) by moving synchronous, XPC-backed network info lookups off the main thread in the iOS plugin, and aligns the Dart method-channel wrapper with safer “empty map” fallbacks for null/error cases. It also bumps the package version and documents the release.

Changes:

  • iOS: dispatch getNetworkInfoResult() to a background DispatchQueue to avoid blocking the main thread; fix WiFi subtype typo (unknwonunknown).
  • Dart: return an empty map when the method-channel result is null or an exception occurs; add tests for these scenarios.
  • Release: bump pubspec.yaml version to 0.0.3 and add a CHANGELOG.md entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/flutter_network_capabilities_method_channel_test.dart Adds unit tests for null and exception behavior from the native channel.
pubspec.yaml Bumps package version 0.0.20.0.3.
lib/flutter_network_capabilities_method_channel.dart Adds try/catch + null handling to return {} for failure cases.
ios/Classes/FlutterNetworkCapabilitiesPlugin.swift Moves network info computation off the main thread; fixes "unknown" subtype typo for WiFi.
CHANGELOG.md Documents the new 0.0.3 changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/flutter_network_capabilities_method_channel.dart
Comment thread ios/Classes/FlutterNetworkCapabilitiesPlugin.swift
@DaniloCharantola DaniloCharantola merged commit e5126df into main Jun 11, 2026
2 checks passed
@DaniloCharantola DaniloCharantola deleted the fix/ios-main-thread-hang branch June 11, 2026 16:43
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.

3 participants