onNavigationStateChange无法在设备iPhone中使用,但可以在模拟器中使用

时间:2019-01-12 07:41:37

标签: reactjs react-native webview payment

我在ios上为我的store在ios中响应本机应用程序。我付钱后想回到我的应用程序。我为此应用程序使用webview,为返回我的应用程序使用webview控件,我使用onnavigatestatechange url事件。 我的代码在EXPO网站模拟器中有效,但在iPhone设备中不起作用,并且在Webview中单击后退按钮后无法返回。 请帮助我。

import React, { Component } from "react";
import styles from "./../../assets/css/Login";
import {
  View,
  Text,
  Image,
  TextInput,
  TouchableOpacity,
  Alert,
  ActivityIndicator,
  AsyncStorage,
  WebView,
  Linking
} from "react-native";
import { Navigator } from "./../Navigator";
import { Header } from "react-native-elements";
import { Mobile } from "./Mobile";

export default class ShowOnline extends Component {
  constructor() {
    super();
    this.state = {
      isLoading: false
    };
    this.webView = null;
  }

  removeAllOrder() {
    var formData = new FormData();
    formData.append("type", "rmall");
    formData.append("number", Mobile["Call"].name);
    return fetch("http://roomarket.ir/LlIi1/user-order.php", {
      method: "POST",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json"
      },
      body: formData
    })
      .then(response => response.json())
      .then(responseJson => {})
      .catch(() => {
        Alert.alert("error");
      });
  }

  _onNavigationStateChange(webViewState) {
    if (webViewState.url.trim() == "return://roomarketfactorsuccess") {
      this.props.navigation.goBack();
      Alert.alert("پرداخت با موفقیت انجام شد");
      this.removeAllOrder();
      this.props.navigation.navigate("MainPage");
    } else if (webViewState.url.trim() == "return://roomarketfactorsuccess") {
      this.props.navigation.goBack();
      Alert.alert("پرداخت با موفقیت انجام نشد");
    }
  }
  render() {
    return (
      <View style={{ flex: 1 }}>
        <Header
          leftComponent={{
            icon: "arrow-back",
            color: "#fff",
            onPress: () => this.props.navigation.goBack()
          }}
          centerComponent={{ text: "پرداخت ", color: "white" }}
          backgroundColor="#95DE5F"
        />
        <WebView
          ref={webView => (this.webView = webView)}
          source={{
            uri:
              "http://factor.roomarket.ir/?number=09398691732&id=100"
          }}
          onNavigationStateChange={this._onNavigationStateChange.bind(this)}
          startInLoadingState={true}
        />
      </View>
    );
  }
}

0 个答案:

没有答案