React Native初心者で、簡単な通知アプリを作っています。
simulatorに、以下のエラーが発生しています。
初歩的なミスだとは思うのですが、なかなか解決の方法がわからず、困っています。
発生している問題・エラーメッセージ
現在、以下のエラーが起きています。
Invariant violation: Native module cannot be null
ソースコード
import React from 'react'; import { View, Button, Platform } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import Constants from 'expo-constants'; import * as Notifications from 'expo-notifications'; import * as Permissions from 'expo-permissions'; import firebase from 'firebase'; import GomiHomeScreen from './src/screens/GomiHomeScreen'; import GomiUsageScreen from './src/screens/GomiUsageScreen'; import GomiSettingScreen from './src/screens/GomiSettingScreen'; import SoundSettingScreen from './src/screens/SoundSettingScreen'; import ReminderSettingScreen from './src/screens/ReminderSettingScreen'; Notifications.setNotificationHandler({ handleNotification: async () => ({ shouldShowAlert: true, shouldPlaySound: false, shouldSetBadge: false, }), }); export default class AppContainer extends React.Component { componentDidMount() { this.registerForPushNotificationsAsync(); this.onReceivedListener = Notifications.addNotificationReceivedListener(this.onReceived); this.onResponseReceivedListener = Notifications.addNotificationResponseReceivedListener( this.onResponseReceived, ); } componentWillUnmount() { this.onReceivedListener.remove(); this.onResponseReceivedListener.remove(); } onReceived = (notification) => { console.log(notification); this.setState('notification'); }; onResponseReceived = (response) => { console.log(response); }; registerForPushNotificationsAsync = async () => { let token; if (Constants.isDevice) { const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS); let finalStatus = existingStatus; if (existingStatus !== 'granted') { const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS); finalStatus = status; } if (finalStatus !== 'granted') { alert('Failed to get push token for push notification!'); return; } token = (await Notifications.getExpoPushTokenAsync()).data; console.log(token); } else { alert('Must use physical device for Push Notifications'); } if (Platform.OS === 'android') { Notifications.setNotificationChannelAsync('default', { name: 'default', importance: Notifications.AndroidImportance.MAX, vibrationPattern: [0, 250, 250, 250], lightColor: '#FF231F7C', }); } }; endPushNotification = async (expoToken) => { const message = { to: expoPushToken, sound: 'default', title: 'Original Title', body: 'And here is the body!', data: { data: 'goes here' }, }; await fetch('https://exp.host/--/api/v2/push/send', { method: 'POST', headers: { Accept: 'application/json', 'Accept-encoding': 'gzip, deflate', 'Content-Type': 'application/json', }, body: JSON.stringify(message), }); } render() { return ( <NavigationContainer> const Tab = createBottomTabNavigator(); <Tab.Navigator tabBarOptions={{ activeTintColor: '#e91e63', labelStyle: { fontSize: 16 }, }} > <Tab.Screen name="ホーム" component={GomiHomeScreen} /> <Tab.Screen name="使い方" component={GomiUsageScreen} /> <Tab.Screen name="通知設定" component={ReminderSettingScreen} /> <Tab.Screen name="通知音" component={SoundSettingScreen} /> </Tab.Navigator> </NavigationContainer> ); } }
###補足情報(FW/ツールのバージョンなど)
"react": "~16.9.0",
"expo": "~37.0.3",
"expo-constants": "~9.0.0",
"expo-notifications": "~0.1.1",
"expo-permissions": "~8.1.0",
javaとjavascliptは別物です。
javaといいはるなら、コンパイル通るようにしてください
あなたの回答
tips
プレビュー