0

I am trying to implement the payment SDK in flutter, it working successfully in Android side and getting trouble to implement the same in iOS.

After the successful payment I am getting the response in

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

How can I send this to flutter?

afsal.an
  • 499
  • 2
  • 6
  • 13

2 Answers2

0

flutter EventCHannel is what you want.

oc、swift:

- (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];
    }
  }];
}

dart:

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);
    }
...
Alexander
  • 91
  • 4
0

Swift version of above solution:

// import Flutter //import 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
        }
user3305074
  • 744
  • 7
  • 19