首页 > 解决方案 > Alert.alert 在 React 本机 iOS 中不起作用,但在 Android 中非常好

问题描述

请检查代码,

import { 
  Alert,
} from 'react-native';

 checkForSendingOtp = () => {
    let hash = 'aBcDeGgd';
    Platform.OS === 'android'
     ? RNOtpVerify.getHash()
        .then(text => {
          hash = text + ''.replace('[', '');
          hash = hash + ''.replace(']', '');
        })
        .then(() => {
          this.sendDataForOtp(hash);
        })
        .catch(console.log)
    : this.sendDataForOtp(hash);
  };

sendDataForOtp(hash) {

axios.post(url,{hash:hash}).then(response=>{
  Alert.alert(
    'Login Failed',
    'Multiple Logins Are Found. \n Logout From All Other Devices to Continue.',
    [
      {
        text: 'Proceed ?',
        onPress: () => {}                       
      },
      {
        text: 'No',
        onPress: () => {},
      },
    ],
    {cancelable: false},
   );
  });
}


render() {
   return (
    <Ripple
        style={{
           position: 'absolute',
           top: 0,
           bottom: 0,
           left: 0,
           right: 0,
              }}
        onPress={this.checkForSendingOtp}
    />
)}

此代码段在 android 中可以正常工作,但在 iOS 中不显示。为什么 ?

注意:- 这是我现在可以分享的大部分代码,编辑过的代码请立即检查,如果您有任何问题,请告诉我。

标签: androidiosreact-native

解决方案


我不完全知道发生了什么,还有一个模型组件用于显示自定义加载,删除模型组件后警报开始工作。


推荐阅读