[ad_1]
I am having a difficulty with Flutter plugin growth, particularly with invoking MethodChannel from native iOS facet to set off Flutter plugin code.
On Android, similar (by way of logic) code described additional works completely for each side (calling from Android / calling from Flutter).
On iOS, I can efficiently obtain Flutter technique calls on native iOS facet, however by no means obtain corresponding technique calls from native iOS facet in Dart plugin code. That is true for iPhone 11(iOS 15.6.1), iPhone X(iOS 15.5) and number of newest iOS simulators I attempted inside my atmosphere.
I take advantage of VSCode/xCode for creating the iOS facet of the plugin.
I’ve tried to downgrade Flutter model (3.0.5 -> 2.10.3), replace/downgrade xCode, clear xCode derived knowledge, reboot {hardware} and so forth.
I’ve created plugin with frequent template flutter create --org com.mycompany --template=plugin --platforms=android,ios t_plugin.
I am utilizing autogenerated plugin_platform_interface: ^2.0.2 (tried 2.1.2) and seen that the bundle itself has not beed up to date for some time (about 7 months).
There’s a comparable difficulty Flutter MethodChannel from iOS to Native not working which seems actually weird by way of attainable workarounds (none of which labored for me).
Any comparable expertise description will likely be appreciated.
Anticipated outcomes:
methodCall.technique in methodChannel.setMethodCallHandler((methodCall) async { ... }is being triggered (or not less than seen whereas debugging inside Dart plugin)- outcome(r) in
self.channel!.invokeMethod("onFinish", arguments: nil, outcome: {(r:Any?) -> () in ... })is being triggered (or not less than seen whereas debugging inside iOS native plugin)
Precise outcomes:
No indicators of triggering the Dart technique name handler whereas invoking native channel technique from iOS (no logs/triggers on any facet).
Code samples
Swift:
import Flutter
import UIKit
public class SwiftTPlugin: NSObject, FlutterPlugin, FlutterApplicationLifeCycleDelegate {
personal var channel: FlutterMethodChannel? = nil
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(identify: "f_plugin_test", binaryMessenger: registrar.messenger())
let occasion = SwiftTestPlugin()
occasion.channel = channel
registrar.addMethodCallDelegate(occasion, channel: channel)
registrar.addApplicationDelegate(occasion)
}
public func deal with(_ name: FlutterMethodCall, outcome: @escaping FlutterResult) {
// Methodology name dealing with from Flutter facet is working high-quality
}
public func end() {
if (self.channel == nil) {
print("CHANNEL IS NIL!"); // By no means comes right here, which suggests channel needs to be legitimate and is present
} else {
print("CHANNEL IS _NOT_ NIL"); // Prints
}
//Tried shorter technique implementations - outcome is similar
self.channel!.invokeMethod("onFinish", arguments: "TEST", outcome: {(r:Any?) -> () in
print(r.debugDescription); // By no means comes right here
})
}
Dart:
import 'bundle:flutter/basis.dart';
import 'bundle:flutter/companies.dart';
import 'bundle:t_flutter/t_flutter.dart';
import 't_flutter_platform_interface.dart';
const methodChannel = MethodChannel("f_plugin_test");
/// An implementation of [VcheckFlutterPlatform] that makes use of technique channels.
class MethodChannelTFlutter extends TFlutterPlatform {
@override
void begin() {
methodChannel.setMethodCallHandler((methodCall) async {
debugPrint("CAUGHT METHOD WITH HANDLER: ${methodCall.technique}"); // By no means comes right here
change (methodCall.technique) {
case "onFinish":
debugPrint("onFinish"); // By no means comes right here
return;
default:
throw MissingPluginException('Not Applied'); // By no means comes right here
}
});
}
flutter physician abstract:
Physician abstract (to see all particulars, run flutter physician -v):
[✓] Flutter (Channel secure, 3.0.5, on macOS 12.1 21C52 darwin-x64, locale
uk-UA)
[✓] Android toolchain - develop for Android gadgets (Android SDK model
32.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the net
[✓] Android Studio (model 2021.2)
[✓] VS Code (model 1.70.2)
[✓] Related machine (3 out there)
[✓] HTTP Host Availability
[ad_2]
