Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.3

* Fix iOS AppHang: dispatch `SCNetworkReachabilityGetFlags` and `CTTelephonyNetworkInfo()`
to a background queue to avoid blocking the main thread during XPC calls.
* Fix typo: `transport_subtype` for WiFi was `"unknwon"`, now `"unknown"`.

## 0.0.1

* Initial release supporting the fields:
Expand Down
8 changes: 5 additions & 3 deletions ios/Classes/FlutterNetworkCapabilitiesPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public class FlutterNetworkCapabilitiesPlugin: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
if (call.method != "getNetworkInfo") {
if call.method != "getNetworkInfo" {
result(FlutterMethodNotImplemented)
return
}
result(getNetworkInfoResult())
DispatchQueue.global(qos: .utility).async {
result(self.getNetworkInfoResult())
Comment thread
rmorbach marked this conversation as resolved.
}
}

private func getNetworkInfoResult() -> [String : String] {
Expand Down Expand Up @@ -48,7 +50,7 @@ public class FlutterNetworkCapabilitiesPlugin: NSObject, FlutterPlugin {
}
} else {
networkInfoResult["transport_type"] = "wifi"
networkInfoResult["transport_subtype"] = "unknwon"
networkInfoResult["transport_subtype"] = "unknown"
}

return networkInfoResult
Expand Down
14 changes: 9 additions & 5 deletions lib/flutter_network_capabilities_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ class MethodChannelFlutterNetworkCapabilities

@override
Future<Map<String, String>> getNetworkInfo() async {
final networkInfo = await methodChannel
.invokeMapMethod<String, String>('getNetworkInfo');
try {
final networkInfo = await methodChannel
.invokeMapMethod<String, String>('getNetworkInfo');

if (networkInfo == null) {
if (networkInfo == null) {
return {};
}

return networkInfo;
} catch (e) {
return {};
}
Comment thread
DaniloCharantola marked this conversation as resolved.

return networkInfo;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_network_capabilities
description: This package allows monitoring of Network Capabilities from Android and iOS devices.
version: 0.0.2
version: 0.0.3
homepage: https://nubank.com/
repository: https://github.com/nubank/flutter-network-capabilities

Expand Down
14 changes: 14 additions & 0 deletions test/flutter_network_capabilities_method_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ void main() {
test('getNetworkInfo', () async {
expect(await platform.getNetworkInfo(), {"testing": "testing"});
});

test('getNetworkInfo returns empty map when native returns null', () async {
channel.setMockMethodCallHandler((MethodCall methodCall) async => null);

expect(await platform.getNetworkInfo(), isEmpty);
});

test('getNetworkInfo returns empty map on PlatformException', () async {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
throw PlatformException(code: 'UNAVAILABLE');
});

expect(await platform.getNetworkInfo(), isEmpty);
});
}