创建React Native NPM包时出现iOS运行异常该如何解决?
我参照了一篇React Native原生模块开发的技术文章创建React Native库,发布后在本地项目中引入使用,Android端运行完全正常,但iOS端运行时抛出如下错误:
TypeError: null is not an object (evaluating '_exampleBridge.default.showMessage').
未捕获错误相关截图
我已经在Xcode13中打开该库项目,确认项目可成功构建,提前感谢各位的解答。
import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, useColorScheme, View, Button } from 'react-native'; import {Colors,Header} from 'react-native/Libraries/NewAppScreen'; import RNExampleBridge from 'example-bridge-1.0.8' const App = () => { const isDarkMode = useColorScheme() === 'dark'; const backgroundStyle = { backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, }; function showToastAlert(){ RNExampleBridge.showMessage() } return ( <SafeAreaView style={backgroundStyle}> <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} /> <ScrollView contentInsetAdjustmentBehavior="automatic" style={backgroundStyle}> <Header /> <View style={{ backgroundColor: isDarkMode ? Colors.black : Colors.white, }}> <View> <Button title="Show Native Message" onPress={() => { showToastAlert() }}/> </View> </View> </ScrollView> </SafeAreaView> ); }; export default App;
内容的提问来源于stack exchange,提问作者Ajay Pillai
相关产品推荐
相关产品推荐

