Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从swift本机代码(AppDelegate)调用(调用)dart方法;“调用方法”;正在android上工作,但不在ios上_Ios_Swift_Xcode_Flutter - Fatal编程技术网

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

如何从swift本机代码(AppDelegate)调用(调用)dart方法;“调用方法”;正在android上工作,但不在ios上,ios,swift,xcode,flutter,Ios,Swift,Xcode,Flutter,我试图在dart中调用函数(“OnRazorPaymentFail”方法) 使用的invokeMethod从ios的AppDelegate类获取文件(main.dart) 颤振通道。但它不工作。RazorPayPaymentFail方法失败 它在安卓系统上启动,但在iOS系统上不起作用 //lib文件夹中的main.dart //main.dart from lib folder class _MyHomePageState extends State<MyHomePage> {

我试图在dart中调用函数(“OnRazorPaymentFail”方法) 使用的invokeMethod从ios的AppDelegate类获取文件(main.dart) 颤振通道。但它不工作。RazorPayPaymentFail方法失败 它在安卓系统上启动,但在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:
    }
  }
//..................................
}}
//lib文件夹中的main.dart
类_MyHomePageState扩展状态{
静态常数razorpay_平台=
const MethodChannel('com.algorin.pf.razorpay');
@凌驾
void initState(){
super.initState();
razorpay_platform.setMethodCallHandler(MyUtilHandler);
}
未来MyUtilHandler(MethodCall MethodCall)异步{
开关(methodCall.method){
“OnRazorPaymentFail”案例:
打印(json.decode(methodCall.arguments));
打破
“OnRazorPaymentSuccess”案例:
processSuccessResponse(json.decode(methodCall.arguments));
打破
违约:
}
}
//..................................
}}
和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 (
        _ application : UIApplication,
        didFinishLaunchingWithOptions launchOptions : [UIApplicationLaunchOptionsKey: Any]?)->
Bool {
    controller = window?.rootViewController as? FlutterViewController;
    RAZORPAY_IO_CHANNEL = FlutterMethodChannel (
        name : "com.algorin.pf.razorpay",
        binaryMessenger : controller
    )
    GeneratedPluginRegistrant.register (with: self);
    return super.application (
        application,
        didFinishLaunchingWithOptions : launchOptions
    );
}

public func onPaymentError (_ code: Int32, description str: String)
{
    print (
        "<<<<<<<<<<< Payment Failed >>>>>>>>>>>>>>>>>>>>>>>>>>>"
    );
    RAZORPAY_IO_CHANNEL.invokeMethod ("onRazorPayPaymentFail", arguments: str);
}
//............
}
//AppDelegate.Swift文件
导入UIKit
进口颤振
进口剃须刀
@UIApplicationMain
@objc类AppDelegate:AppDelegate,
RazorPaymentCompletionProtocol{
//..............
var控制器:VIEWCONTROLLER!;
var RAZORPAY_______________________________!;
重写func应用程序(
_应用程序:UIApplication,
didFinishLaunchingWithOptions启动选项:[UIApplicationLaunchOptions:任何]?)->
布尔{
控制器=窗口?rootViewController作为?视图控制器;
RAZORPAY\u IO\u通道=通道(
名称:“com.algorin.pf.razorpay”,
binaryMessenger:控制器
)
GeneratedPluginRegistrant.register(with:self);
返回超级应用程序(
应用
didFinishLaunchingWithOptions:启动选项
);
}
公共函数onPaymentError(uu代码:Int32,说明str:String)
{
印刷品(
">>>>>>>>>>>>>>>>>"
);
RAZORPAY_IO_CHANNEL.invokeMethod(“onRazorPayPaymentFail”,参数:str);
}
//............
}

您好,您找到解决方案了吗?-事实上,我也面临着同样的问题,我刚刚尝试了更新版本的颤振,它工作得很好——你可能早就知道了@JonCook,你以前和新版本的颤振是什么?抱歉,不确定旧版本是什么-新版本是:$颤振-版本颤振1.9.1+修补程序。6•通道稳定•框架•版本68587a0916(9周前)•2019-09-13 19:46:58-0700引擎•版本b863200c37工具•Dart 2.5.0[john@MacBook-节拍器