0

我正在尝试在 Flutter 中实现支付 SDK,它在 Android 端成功运行,但在 iOS 中实现相同时遇到了麻烦。

付款成功后,我收到了回复

 func qpResponse(_ response: NSDictionary) {
                        print("Response Inside customer app:",response)
                //Perform your actions with the response
  
  }

我怎样才能把这个发送到颤振?

4

2 回答 2

0

颤振 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);
    }
...
于 2021-07-06T02:14:00.210 回答
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
        }
于 2021-07-29T18:12:06.347 回答