point-source / dart_ping

Multi-platform network ping utility for Dart
31 stars 14 forks source link

Not support for iOS ? #6

Closed AllanChen closed 3 years ago

AllanChen commented 3 years ago

I use dart_ping to check my network reachable. Android work. But I got an error on the iOS Platform like this.

flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════ flutter: The following UnimplementedError was thrown: flutter: Ping not supported on this platform flutter: flutter: When the exception was thrown, this was the stack: flutter: #0 getPing (package:dart_ping/src/native_ping.dart:20:7) flutter: #1 new Ping (package:dart_ping/src/dart_ping_base.dart:10:7) flutter: #2 NetMgr._pingNetwork (package:tktalk/provide/netmgr.dart:368:27) flutter: #3 NetMgr.init (package:tktalk/provide/netmgr.dart:451:5) flutter: #4 NetMgr.connectServer (package:tktalk/provide/netmgr.dart:524:10) flutter: #5 InitPageState._checkVersionCode (package:tktalk/pages/init_page.dart:232:27) flutter: #6 InitPageState._checkVersion (package:tktalk/pages/init_page.dart:143:7) flutter: #7 InitPageState.initState.<anonymous closure> (package:tktalk/pages/init_page.dart:135:64) flutter: (elided 18 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch) flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════

I saw the code is missing the iOS Platform case, so I write the code like this. Ping getPing( String host, int count, double interval, double timeout, bool ipv6) { switch (Platform.operatingSystem) { case 'android': case 'fuchsia': case 'ios': case 'linux': return PingLinux(host, count, interval, timeout, ipv6); case 'macos': return PingMac(host, count, interval, timeout, ipv6); case 'windows': return PingWindows(host, count, interval, timeout, ipv6); default: throw UnimplementedError('Ping not supported on this platform'); } } It is, right?

AllanChen commented 3 years ago

Maybe I need a demo on iOS Platform

point-source commented 3 years ago

Yeah for some reason, I can't figure out how to get pub.dev not to display iOS. If I explicitly state the flutter platform support, then pub.dev drops the "Native" flag. So I either have a false positive iOS flag or a false negative Native flag. Since this package supports native dart, I prefer to have that display and then just throw an error on iOS.

If you do not need native support but do need iOS, check out flutter_icmp_ping by zuvola.

tanzilzubair commented 3 years ago

So are there any plans to support iOS?

point-source commented 3 years ago

@tanzilzubair Yes, I actually just made some progress on that last week. It will likely get published as a new package though (called flutter_ping) because I need to use ffi or plugin channels to support iOS and as far as I can tell, adding that means depending on the flutter sdk, which removes dart native support from the current package. I don't really want to do that since I myself use this package for pure dart backend projects.

TLDR: Yes, I intend to upload flutter_ping with iOS support over the next week or so

phan-dev commented 3 years ago

@point-source How's your new plugin?

point-source commented 3 years ago

@phan-dev It's going alright. I have it successfully building and pinging on iOS via dart ffi -> swift -> Obj-C GBPing package.

The issue is getting the data back. Trying to get native ports working so I can return the ping data asynchronously. Unfortunately, there is very little documentation about how to accomplish this and most of the existing material covers c++ rather than swift. So it's basically held up on this issue unless I get native ports working in swift.

point-source commented 3 years ago

Preliminary iOS support (workaround) is now available via this plugin: https://pub.dev/packages/dart_ping_ios See the included docs for info on how to enable it.

Once the dart FFI improves, I will rework this but for now it should be fine.

ivirtex commented 2 years ago

@point-source How's the progress of flutter_ping? Have you been able to get asynchronous callbacks working from dart:ffi?

point-source commented 2 years ago

If you need ping working on iOS, use the plugin mentioned in the previous comment. (dart_ping_ios)

If you are just asking whether it is using method channels or async callbacks, it is using method channels still. I was not able to get it working using async callbacks. In practice though, this has not been a limiting factor. Are you having an issue with the existing iOS implementation?

ivirtex commented 2 years ago

Well, I am working on a library that finds devices on a local network by pinging every IP in the subnet. The problem is that dart_ping_ios is dependant on Flutter itself, which makes my package unusable on platforms other than iOS and Android. That's why I am asking about progress with your new plugin.

point-source commented 2 years ago

Ah, that makes sense. I was trying to accomplish the same thing and ran into the same problem.

Unfortunately, even using ffi would require flutter since I would have to find a way to include a swift compiled binary/library and dart does not provide a way to include assets like that or declare pod dependencies. So even with ffi, I would need to import the flutter sdk so that I could include assets or depend on a swift/obj-c pod.

That's why my current ios implementation is broken out into a plugin. I didn't want to restrict dart_ping to flutter only.