When integrating a Flutter app with native iOS APIs—CoreNFC, NetworkExtension for VPN, AVFoundation with custom session configurations—Dart packages often fall short. They either don't cover the required functions or lag two major SDK versions behind. In such cases, you write a Platform Channel manually. Common implementation errors—double invocation of FlutterResult, eventSink leaks, ignoring thread safety—lead to crashes that are hard to debug. Order a turnkey Platform Channel development: we assess your project in one day and implement the channel handling all edge cases. This saves up to 40% of debugging time and guarantees stability on iOS 16+.
What is a Platform Channel in Flutter?
Platform Channel is a two-way communication mechanism between Dart code and native iOS code (Swift or Objective-C). It enables calling native APIs not directly accessible from Dart, such as reading NFC, controlling the camera via AVFoundation, or working with Keychain. The channel uses serialization via StandardMessageCodec and thread synchronization. Flutter documentation provides basic templates, but real projects require accounting for many nuances.
How to Choose the Right Platform Channel Type?
Flutter provides three channel types for different scenarios:
| Type | Principle | When to Use | Peculiarities |
|---|---|---|---|
| MethodChannel | Request/response | One-time calls: biometrics, Keychain | Call FlutterResult strictly once |
| EventChannel | Data stream from native to Dart | Continuous data: sensors, Bluetooth | Nil eventSink in onCancel |
| BasicMessageChannel | Bidirectional exchange with custom codec | Complex structures not fitting StandardMessageCodec | Rare, only for non-standard binary protocols |
For 80% of tasks, MethodChannel suffices. It's 2–3 times easier to debug than EventChannel. EventChannel is chosen when data arrives continuously—e.g., accelerometer readings every 100 ms. BasicMessageChannel is applied in exceptional cases.
Why is Proper FlutterResult Invocation Important?
FlutterResult is an Objective-C callback passed to Swift for the response. The main rule: call it exactly once. Calling it twice causes a runtime crash with message Call to FlutterResult callback after it has been released. A typical pitfall: the AVCaptureSession.startRunning method executes asynchronously and finishes on a background queue. If you don't dispatch the result via DispatchQueue.main.async, the response may arrive on an unexpected thread, leading to non-deterministic behavior. In 30% of projects we review, the double-call error appears.
channel.setMethodCallHandler { [weak self] call, result in guard call.method == "startCapture" else { result(FlutterMethodNotImplemented) return } self?.session.startRunning(completion: { success, error in DispatchQueue.main.async { if let error = error { result(FlutterError(code: "CAPTURE_ERROR", message: error.localizedDescription, details: nil)) } else { result(success) } } }) } How to Avoid Leaks with EventChannel?
FlutterEventSink must be nilified in onCancel:
final class SensorStreamHandler: NSObject, FlutterStreamHandler { private var motionManager = CMMotionManager() private var eventSink: FlutterEventSink? func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { eventSink = events motionManager.startAccelerometerUpdates(to: .main) { [weak self] data, _ in guard let data = data else { return } self?.eventSink?(["x": data.acceleration.x, "y": data.acceleration.y]) } return nil } func onCancel(withArguments arguments: Any?) -> FlutterError? { motionManager.stopAccelerometerUpdates() eventSink = nil // critical: without this, there will be accesses to a deallocated object return nil } } Omitting eventSink = nil means getting EXC_BAD_ACCESS after a few minutes of work. Our practice shows that this error occurs in 70% of projects without code review.
Serialization via StandardMessageCodec: Pitfalls
StandardMessageCodec supports Uint8List, which helps when transferring small binary data (image preview, encrypted payload). But for objects more complex than a dictionary, manual serialization is still needed. Attempting to pass Data directly without converting to FlutterStandardTypedData leads to silent failure: Dart receives null instead of data. Using ready-made solutions reduces the risk of such errors by 50%.
How to Test a Platform Channel in 3 Steps
- Write a Dart test with
MockMethodCallHandlerto simulate the native side's response. Verify your service correctly handles success and error. - Isolate the Swift handler: create a mock for dependencies (e.g.,
AVCaptureSession) and testresultinvocation in different scenarios. - Test integration on a real device—many iOS APIs (NFC, Bluetooth) are unavailable in the simulator.
What's Included
- Contract documentation (methods, types, error codes).
- Native Swift handler with unit test coverage (XCTest).
- Dart service with typed API and mock handlers for testing.
- Access to a repository with usage examples and README.
- Support for 30 days after delivery (integration consultations).
Development Stages of a Platform Channel
| Stage | Description | Duration |
|---|---|---|
| Contract design | Define methods, arguments, error codes | 0.5 day |
| Swift handler implementation | Write thread-safe code | 1–2 days |
| Dart typed API service | Wrap MethodChannel in a service class | 0.5 day |
| Edge case handling | Device doesn't support feature, user denied permission | 0.5–1 day |
| Unit tests (Dart + Swift) | Isolated testing of each side | 1–2 days |
| Real device testing | Many iOS APIs unavailable in simulator | 1 day |
Total: 3–5 days. Simple MethodChannel for one system call — 2–3 days with tests. EventChannel with continuous data flow — 4–5 days. Pricing is quoted individually after requirements analysis. Get a consultation — we assess your project within a day.







