gpt4 book ai didi

ios - AlertIOS 未定义错误(React Native)

转载 作者:行者123 更新时间:2023-11-28 23:28:37 27 4
gpt4 key购买 nike

我正在尝试使用 AlertIOS在一个全新的 React Native 项目中,但由于某种原因,我遇到了与 undefined 相关的错误。

代码的相关部分:

import { AlertIOS } from 'react-native';

// Callback for a button press
const _alert = () => {
AlertIOS.alert('title', 'text')
}

如果我未处于 Debug模式,单击按钮后会收到错误undefined is not an object (evaluating '_reactNative.AlertIOS.alert')

调试时,错误变为Cannot read propertyalert of undefined,并且AlertIOS具有下面打印中显示的值,这似乎不正确。

此外,如果我只使用 Alert.alert,它会起作用(显然会更改导入)。

enter image description here

最佳答案

在 RN 0.61 中,AlertIOS 功能现在是 Alert 本身的一部分。例如,您可以执行以下操作,而不是 AlertIOS.prompt:

import {Alert} from 'react-native';

Alert.prompt('Alert Title', 'message', [
{
text: 'ok',
onPress: str => console.log('Entered string: ' + str),
},
{
text: 'Cancel',
onPress: () => console.log('Pressed Cancel!'),
style: 'cancel',
},
]);

参见 this问题详情

关于ios - AlertIOS 未定义错误(React Native),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57647898/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com