小编Sub*_*ana的帖子

如何从 swift 本机代码(AppDelegate)调用(Invoke)dart 方法?“invokeMethod”在 android 上工作,但在 ios 上不起作用

我正在尝试使用flutter通道的invokeMethod从ios的AppDelegate类调用dart文件(main.dart)中的函数(“onRazorPayPaymentFail”方法)。但它不起作用。onRazorPayPaymentFail方法在Android上触发。但在iOS中它不管用。

//lib 文件夹中的 main.dart

//main.dart from lib folder
class _MyHomePageState extends State<MyHomePage> {
  static const razorpay_platform =
      const MethodChannel('com.algorin.pf.razorpay');

  @override
  void initState() {
    super.initState();
    razorpay_platform.setMethodCallHandler(myUtilsHandler);
  }

  Future<dynamic> myUtilsHandler(MethodCall methodCall) async {
    switch (methodCall.method) {
      case 'onRazorPayPaymentFail':
        print(json.decode(methodCall.arguments));
        break;
      case 'onRazorPayPaymentSuccess':
        processSuccessResponse(json.decode(methodCall.arguments));
        break;
      default:
    }
  }
//..................................
}}
Run Code Online (Sandbox Code Playgroud)

和 AppDelegate.Swift 文件

//AppDelegate.Swift  file
import UIKit 
import Flutter 
import Razorpay 
@UIApplicationMain 
@objc class AppDelegate : FlutterAppDelegate,
RazorpayPaymentCompletionProtocol {
    //..............
    var controller : FlutterViewController!;
    var RAZORPAY_IO_CHANNEL : FlutterMethodChannel!;

    override func application (
        _ …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift flutter

5
推荐指数
0
解决办法
1904
查看次数

标签 统计

flutter ×1

ios ×1

swift ×1

xcode ×1