Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用AppState.addEventListener时Android端会不正常的触发active状态 #43

Open
NapChen opened this issue Nov 24, 2021 · 0 comments

Comments

@NapChen
Copy link

NapChen commented Nov 24, 2021

componentDidMount() {
    Alipay.setAlipayScheme('uiwjspay');
    AppState.addEventListener('change', this._handleAppStateChange);
  }
  componentWillUnmount(){
    AppState.removeEventListener('change', this._handleAppStateChange)
  }
  // [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'inactive'
  // [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'background'
  // [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'active'
  // [info][tid:com.facebook.react.JavaScript] 'nextAppState:res:', null
  _handleAppStateChange = (nextAppState) => {
    console.log('nextAppState:', nextAppState)
    if(nextAppState==='active'){
      Linking.getInitialURL().then(res => {
        console.log('nextAppState:res:', res)
      })
    }
  }
  aliPay = () => {
    // return_url=
    const payInfo = `...`;
    Alipay.alipay(payInfo, (resule) => {
      console.log('resule-->>>', resule)
    });
  }

代码逻辑与这个一致,但是Android端在调起支付宝支付时,我的应用首先会进入background,在弹出支付宝支付界面时,会触发一次active状态(正常情况下不应该有),然后再次进入background,这会导致触发在_handleAppStateChange中的逻辑。我在接入微信支付时调起微信支付不存在这样的问题。另外此插件在iOS端也是正常的
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant