我正在尝试在 Flutter 中实现支付 SDK,它在 Android 端成功运行,但在 iOS 中实现它时遇到了麻烦。
付款成功后我收到回复
func qpResponse(_ response: NSDictionary) {
print("Response Inside customer app:",response)
//Perform your actions with the response
}
如何将其发送到 Flutter?
答案 0 :(得分:0)
flutter EventCHannel 就是你想要的。
oc、快速:
- (void)initMethodChannel{
self.methodChannel = [FlutterMethodChannel methodChannelWithName:@"MethodChannelPlugin" binaryMessenger:self.flutterViewController];
MainViewController* __weak weakSelf = self;
[self.methodChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
if ([@"send" isEqualToString:call.method]) {
result([NSString stringWithFormat:@"MethodChannelPlugin收到:%@",call.arguments]);//返回结果给Dart);
[weakSelf sendShow:call.arguments];
}
}];
}
飞镖:
import 'package:flutter/services.dart';
...
static const MethodChannel _methodChannelPlugin =
const MethodChannel('MethodChannelPlugin');
...
String response;
try {
response = await _methodChannelPlugin.invokeMethod('send', value);
} on PlatformException catch (e) {
print(e);
}
...
答案 1 :(得分:0)
上述解决方案的 Swift 版本:
// 导入 Flutter //导入 FlutterPluginRegistrant
let flutterEngine = FlutterEngine(name: "io.flutter", project: nil)
flutterEngine?.run(withEntrypoint: nil)
GeneratedPluginRegistrant.register(with: self.flutterEngine!)
let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
let flutterMethodChannel = FlutterMethodChannel(name: "MethodChannelPlugin",
binaryMessenger: flutterViewController.binaryMessenger)
flutterMethodChannel.setMethodCallHandler { _, _ in
//receive call here Swift
}