在 react-native 中对 android 和 IOS 发出警报 [英] alert for both android and IOS in react-native

查看:35
本文介绍了在 react-native 中对 android 和 IOS 发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试显示警报消息,我尝试了不同的方式,例如 alert、AlertIOS、Alert.alert

  • AlertIOS 可在 iPhone 中运行,但在 android 中不起作用,警报也相同在 Docs 中,我看到 Alert.alert 对 Android 和 IOS 都有效,但我得到一个错误,如 undefined is not an object(评估Alert.alert")我是这样写的:
<块引用>

Alert.alert('Alert', 'email is not valid, Please enter right email', [{text: 'Ok'}]);

我收到了这样的错误:

任何人都建议如何在Android和IOS中在react-native中显示警报非常感谢任何帮助

解决方案

您确定从正确的路径包含它吗?当我从 react 库导入 Alert 而不是 react-native 时,我遇到了同样的错误.

所以工作的东西是:

import React, { Component } from 'react';从'react-native'导入{查看,警报};

和不工作的是:

import React, { Component, Alert } from 'react';从'react-native'导入{视图};

Hai i am trying to show alert message, i tried different ways like alert,AlertIOS,Alert.alert

  • AlertIOS is working in IPhone but not working in android and alert also same In Docs i saw that Alert.alert will work for both Android an IOS,But i got an error like undefined is not an object(evaluating 'Alert.alert') I wrote like this:

Alert.alert('Alert', 'email is not valid, Please enter correct email', [{text: 'Ok'}]);

I got an error like this:

Any one give suggestions that how to show the alert in Android and IOS in react-native Any help much appreciated

解决方案

Are you sure you are including it from the correct path? I get the same error when I imported Alert from react library and NOT react-native.

so the working thingie is:

import React, { Component } from 'react';
import { View, Alert } from 'react-native';

and the non-working one was:

import React, { Component, Alert } from 'react';
import { View } from 'react-native';

这篇关于在 react-native 中对 android 和 IOS 发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆