ITADN

[iOS] When `applePayAPIEnabled` is `true`, javascript handler no longer working

#2785Closedanderscheow 创建于 2026-02-26
bug
A
anderscheowcommented
### Is there an existing issue for this? - [x] I have searched the existing issues ### Current Behavior Javascript handler's callback not invoked ### Expected Behavior Javascript handler's callback should be invoked ### Steps with code example to reproduce <details> <summary>Steps with code example to reproduce</summary> ```dart import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; WebViewEnvironment? webViewEnvironment; Future main() async { WidgetsFlutterBinding.ensureInitialized(); if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) { final availableVersion = await WebViewEnvironment.getAvailableVersion(); assert(availableVersion != null, 'Failed to find an installed WebView2 Runtime or non-stable Microsoft Edge installation.'); webViewEnvironment = await WebViewEnvironment.create( settings: WebViewEnvironmentSettings(userDataFolder: 'YOUR_CUSTOM_PATH')); } if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) { await InAppWebViewController.setWebContentsDebuggingEnabled(kDebugMode); } runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => new _MyAppState(); } class _MyAppState extends State<MyApp> { InAppWebViewSettings settings = InAppWebViewSettings( applePayAPIEnabled: true, isInspectable: kDebugMode, mediaPlaybackRequiresUserGesture: false, allowsInlineMediaPlayback: true, iframeAllow: "camera; microphone", iframeAllowFullscreen: true); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text("JavaScript Handlers")), body: SafeArea( child: Column(children: <Widget>[ Expanded( child: InAppWebView( webViewEnvironment: webViewEnvironment, initialData: InAppWebViewInitialData(data: """ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> </head> <body> <h1>JavaScript Handlers</h1> <script> window.addEventListener("flutterInAppWebViewPlatformReady", function(event) { window.flutter_inappwebview.callHandler('handlerFoo') .then(function(result) { // print to the console the data coming // from the Flutter side. console.log(JSON.stringify(result)); window.flutter_inappwebview .callHandler('handlerFooWithArgs', 1, true, ['bar', 5], {foo: 'baz'}, result); }); }); </script> </body> </html> """), initialSettings: settings, onWebViewCreated: (controller) { controller.addJavaScriptHandler( handlerName: 'handlerFoo', callback: (JavaScriptHandlerFunctionData data) { // return data to the JavaScript side! return {'bar': 'bar_value', 'baz': 'baz_value'}; }); controller.addJavaScriptHandler( handlerName: 'handlerFooWithArgs', callback: (JavaScriptHandlerFunctionData data) { print(data); // it will print: // JavaScriptHandlerFunctionData{args: [1, true, [bar, 5], {foo: baz}, {bar: bar_value, baz: baz_value}], isMainFrame: true, origin: , requestUrl: about:blank} }); }, onConsoleMessage: (controller, consoleMessage) { print(consoleMessage); // it will print: {message: {"bar":"bar_value","baz":"baz_value"}, messageLevel: 1} }, ), ), ]))), ); } } ``` </details> ### Stacktrace/Logs <details> <summary>Stacktrace/Logs</summary> </details> ### Flutter version v3.35.5 ### Operating System, Device-specific and/or Tool iOS 26 ### Plugin version v6.1.5 ### Additional information _No response_ ### Self grab - [ ] I'm ready to work on this issue!
关闭于 2026-02-26 3 条评论