- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Flutter 项目,试图在 Flutter 和 iOS Native 之间建立双向通信。到目前为止,它从 Flutter 到 iOS 都运行良好,但反之则无声。当我从 iOS 调用该方法时,没有任何反应。没有消息,没有错误,什么都没有。
我在 iOS 上创建 MethodChannel 是这样的:
let channel = FlutterMethodChannel(
name: "paymentview",
binaryMessenger: controller.binaryMessenger
)
channel.setMethodCallHandler({
(call: FlutterMethodCall, result: FlutterResult) -> Void in
if (call.method == "initialize") {
} else if(call.method == "authorize") {
}
})
在 Flutter 方面像这样:
_channel = new MethodChannel('paymentview');
_channel.setMethodCallHandler(methodCallHandler);
Future<dynamic> methodCallHandler(MethodCall methodCall) async {
switch (methodCall.method) {
case 'authorized':
print("authorized");
return null;
default:
throw PlatformException(code: 'Not implemented', message: 'Not implemented');
}
}
在 Flutter 上,我调用如下方法:
_channel.invokeMethod('authorize');
而且效果很好。在 iOS 中收到调用。但是在 iOS 端我调用了这样的方法:
DispatchQueue.main.async {
self.channel.invokeMethod("authorized", arguments: nil)
}
Flutter 端什么也没有发生。没有消息,没有错误,什么都没有。我已经尝试了多种变体,包括创建多个 channel (每个 channel 一个)、动态 channel ID 等等,但它在 Flutter 方面是沉默的。有什么想法吗?
编辑:我已经从 iOS 端对此进行了调试,它确实有效。我从 Dart 代码中获取返回值。但是,当我调试 Dart 代码时,没有命中断点。如果我尝试修改 Dart 中的某些状态,什么也不会发生...
Edit2:它似乎在使用运行器项目从 XCode 运行时有效,但在从 Android Studio 运行 Flutter 项目时却无效。
最佳答案
如评论中所述,这突然开始工作而没有任何代码更改。我重启了我的 mac 几次,刷新了 Android Studio 等。突然间它工作了。
关于ios - 从 iOS 到 Native 的 Flutter MethodChannel 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62967887/
有没有办法在不需要时处理 MethodChannel/EventChannel ?我问是因为我想为对象创建多个方法/事件 channel 。 例子: class Call { ... fields
我的应用程序将文件发送到 ftp 服务器。我通过MethodChannel在android上用java发送文件。 这些部分可以在单线程中完成所有工作。但我想发送带有 AsyncTask (java)
所以我在大约 4 个月前写了一个 Flutter 应用程序。现在我想做一个小改动,但我不能再编译应用程序了,因为 GeneratedPluginRegistrant.registerWith(this
Flutter docs 中的示例将他们正在使用的 MethodChannel(与 native 主机通信)直接在使用它的 Widget 中声明为 static const。为了将其中一些分离,我正在
我正在尝试使用一些 native 代码为 Flutter 创建一个 Facebook 身份验证插件。我已经让代码在一个完全 native 的测试项目上工作,但无法让它在 android 插件项目中工作
在Flutter中,平台 channel 分为三种,想了解一下它们的区别。 最佳答案 这些 channel 用于在原生代码(项目内的插件或原生代码)和 Flutter 框架之间进行通信。 方法 cha
得到这个奇怪的错误。似乎 MethodChannel 正在转换为 int 而不是 bool? 06-07 00:16:26.589 3678 4993 E flutter : [ERROR:top
我在应用程序关闭时尝试打开 android Activity 时失败。在下面的代码中看到,当我收到来自 firebase 的数据通知时,当应用程序在后台时,我应该使用 MethodChannel 打开
我正在编写一个原生插件,在某些情况下,它必须调用应用程序的 Flutter 部分中的函数,该插件是用 Dart 编写的。它是如何实现的,解释如下: https://flutter.io/platfor
我有一个 flutter 项目(插件),它也使用一些 native java 代码。为了在 dart 和 java 之间进行通信,我使用了 MethodChannel.invokeMethod。这在
我正在编写一个原生插件,在某些情况下,它必须调用应用程序的 Flutter 部分中的函数,用 Dart 编写。它是如何实现的,在这里解释: https://flutter.io/platform-ch
我正在尝试这里的示例 https://flutter.dev/docs/development/platform-integration/platform-channels#step-1-create
我有一个 Flutter 项目,试图在 Flutter 和 iOS Native 之间建立双向通信。到目前为止,它从 Flutter 到 iOS 都运行良好,但反之则无声。当我从 iOS 调用该方法时
好吧,我正在尝试使用 PlatformChannels 从 flutter 导入 Java 代码,我在 Ubuntu 上并且收到该错误,也许这是一个 Java 错误,请创建我的项目 flutter c
在开始我的问题之前,我想指出这个问题并不相似。 Difference between writing platform specific code vs dart:ffi code .在这里,发问者问
我是一名优秀的程序员,十分优秀!