错误(WebView、Expo Intent(开放支付方式:KakaoPay、NaverPay)

问题描述 投票:0回答:1

有谁知道如何使用 React navite Webview 和 expo Intent-launcher 打开应用程序(kakaopay、naver pay、payco...?)。

我不知道为什么这不起作用(它在 iOS 上只需 Linking.openURL(url)),但在 Android 上还没有任何作用

这是我的基本配置:("react-native": "0.74.3", "expo": "~51.0.22")

import * as IntentLauncher from "expo-intent-launcher";

const payUrl = "https://......."
pay
const onShouldStartLoadWithRequest = (event: any) => {
    console.log(event);
    const url = event.url || "";

    if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("about:blank")) {
      return true;
    }
    console.log("url", url);
    if (Platform.OS === "android") {
      try {
        IntentLauncher.startActivityAsync("android.intent.action.VIEW", {
          data: url,
        })
          .then(() => {
            console.log("Payment gateway opened successfully");
          })
          .catch((error) => {
            console.error("Failed to open payment gateway:", error);
          });
      } catch (error) {
        console.error("Error launching intent:", error);
      }
      return false;
    } else {
      Linking.openURL(url).catch((err) => {
        console.log({ err });
        Alert.alert(
          "App execution failed. If it is not installed, please press the install button."
        );
      });
      return false;
    }
  };

return (
    <View className="flex-1">
      <WebView
        ref={handleSetRef}
        useWebKit={false}
        scalesPageToFit={Platform.OS !== "ios"}
        originWhitelist={["*"]}
        source={{ uri: payU`your text`rl }}
        javaScriptEnabled={true}
        onLoad={NativeToWeb}
        onError={errorHandler}
        onMessage={WebToNative}
        onNavigationStateChange={onNavigationStateChange}
        onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
        setSupportMultipleWindows={false}
        javaScriptCanOpenWindowsAutomatically={true}
      />
    </View>
  );

我尝试使用react-native-send-intent库 库,但由于它与世博会不兼容,我想我应该尝试他们的(世博会 IntentLauncher)。

在 iOS 上我没有问题,但是当我在构建 .apk 后使用 Android(设备)启动时,出现错误。

所以我在 AndroidManifest.xml 中添加了包,例如:

<package android:name=“com.kakao.talk” /> 
<package android:name=“com.samsung.android.spay” /> 

但是没有任何作用

react-native android-intent expo payment
1个回答
0
投票

添加此:

if (Platform.OS === "android") {
  if (url.startsWith("intent:")) {
    const intents = url.split("#Intent;");
    const path = intents[0] || "";
    const query = intents[1] || "";
    const params = {};
    query.split(";").map((each) => {
      if (each.includes("=")) {
        const pairs = each.split("=");
        params[pairs[0]] = pairs[1];
      }
    });
    const scheme = params?.scheme;
    const packageName = params?.package;
    const data = path.replace("intent://", `${scheme}://`);
    try {
      IntentLauncher.startActivityAsync("android.intent.action.VIEW", {
        data: data,
      })
        .then(() => {
          console.log("Payment gateway opened successfully");
        })
        .catch((error) => {
          console.error("Failed to open payment gateway:", error);
        });
    } catch (error) {
      console.log("Error launching intent in if condition", error);
    }
  } 
© www.soinside.com 2019 - 2024. All rights reserved.