0

Is it possible to access NSURLSession and related types via FFI from dart? I would like to use this bindings with Flutter on iOS.

If yes, could that be done with dart:ffigen and how would I have to configure it? There are lots of samples for ffi, but I did not find accessing system frameworks.

delixfe
  • 2,471
  • 1
  • 21
  • 35
  • Why are you trying to use FFI instead of just a normal plugin? You even tagged your question [flutter-plugin]. – Christopher Moore Apr 16 '21 at 22:49
  • With a normal plugin I had to pipe everything through platform channels. This means implementation on the native and on the dart side. Additionally, there might be a performance overhead. – delixfe Apr 16 '21 at 23:46
  • 1
    Why wouldn't this be possible? There's a whole win32 library using ffi. – Christopher Moore Apr 16 '21 at 23:52
  • That sounds great. Do you have a link? All the samples only include local headers.. – delixfe Apr 17 '21 at 00:03
  • https://pub.dev/packages/win32 – Christopher Moore Apr 17 '21 at 00:05
  • @ChristopherMoore: I did some more research. `NSUrlSesssion` belongs to Apple's foundation framework and is implemented in Objective-C. FFI supports native C APIs. Thus, I would say it is not possible to create bindings for `NSUrlSession`. – delixfe Apr 20 '21 at 16:40
  • That's why you should use a normal plugin as suggested above. – Richard Heap May 03 '21 at 21:59
  • @RichardHeap: As written above, I was looking into FFI as platform channels need implementation on the native and the dart side. Additionally, there is a performance overhead, especially when transporting bigger byte arrays. – delixfe May 05 '21 at 07:26
  • 1
    It is possible to go from Dart->ffi->C[++]->ObjectiveC but it's horribly complicated. – Richard Heap May 06 '21 at 13:51

1 Answers1

1

The Dart team just released cupertino_http networking package for macOS/iOS which leverages the new Objective-C interop support to wrap Apple’s networking NSURLSession library.

More info: https://medium.com/dartlang/dart-2-18-f4b3101f146c

David Miguel
  • 12,154
  • 3
  • 66
  • 68