使用传递第三方站点,该站点使用Stripe。他们有谷歌支付,但谷歌支付按钮没有出现使用反应本机Webview。如果我使用第三方网站url并在Android上通过Chrome查看它,那么Google Pay就会出现。反应本地Webview有什么问题吗,还是我需要从一个应用程序传递到另一个pay视图,让第三方站点与Google pay一起出现?
发布于 2022-01-14 21:32:32
简单地说,这是由于在一般情况下使用WebViews,在移动环境中,您需要使用本土整合。除非您也控制站点,否则您无法做任何事情,因为您需要使用本机实现。
根据谷歌的文档的说法,对于一般的WebViews
对于使用WebViews的安卓应用程序,您必须调用特定于平台的。有关示例,请参见将JavaScript代码绑定到Android代码。
在绑定示例中,它们公开了一个JS接口,用于在来自WebView的本地应用程序之间进行通信。您可以通过在WebView中使用webview中的injectJavaScript
函数和以文档形式的这里在and视图上运行injectJavaScript
来实现这种通信。
import React, { Component } from 'react';
import { View } from 'react-native';
import { WebView } from 'react-native-webview';
export default class App extends Component {
render() {
// Triggers an alert in the native app.
const html = `
<html>
<head></head>
<body>
<script>
setTimeout(function () {
window.ReactNativeWebView.postMessage("Hello!")
}, 2000)
</script>
</body>
</html>
`;
const run = `
document.body.style.backgroundColor = 'blue';
true;
`;
// Will update the background in the web view.
setTimeout(() => {
this.webref.injectJavaScript(run);
}, 3000);
return (
<View style={{ flex: 1 }}>
<WebView
ref={(r) => (this.webref = r)}
source={{ html }}
onMessage={(event) => {
alert(event.nativeEvent.data);
}}
injectedJavaScript={runFirst}
/>
</View>
);
}
如果您有消息传递之间的应用程序和webview之间的工作,那么您应该能够处理传递,以检查谷歌支付支持(并提供任何经验的网页视图)。您可以从视图中触发本地支付流。
https://stackoverflow.com/questions/66003027
复制相似问题