文章链接:https://juejin.cn/post/6908232699673722888
目的: 实现一个flutter调用原生ios相册的功能,并传递照片
flutter的操作
flutter用来传递的模块叫channel
,这里我们使用MethodChannel
// 注册通道
MethodChannel _methodChannel = MethodChannel("picture_page");
// 发送消息
_methodChannel.invokeMapMethod("picture");
// 接收消息
_methodChannel.setMethodCallHandler((call) async {
if (call.method == "picture-ios") {
print("ios call arguments --- " + call.arguments);
}
});
iOS的操作
iOS端用来传递的模块是FlutterMethodChannel
//注册通道
methodChannel = FlutterMethodChannel(name: "picture_page", binaryMessenger: vc as! FlutterBinaryMessenger)
// 发送消息
self?.methodChannel.invokeMethod("picture-ios", arguments: "img")
//接收消息
methodChannel.setMethodCallHandler { (call, result)