Sub*_*ana 5 xcode ios swift flutter
我正在尝试使用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 (
_ 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);
}
//............
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1904 次 |
| 最近记录: |