expo でプッシュ通知を実装しているのですが、以下のエラーが発生しました。
公式のdocumentを参考に書いているのですが、registerForPushNotificationを定義づけるように警告が出ています。
どなたかわかる方、ご指摘いただけると幸いです。
HomeScreenのコード
ReactNative
1//一部抜粋 2 3Notifications.setNotificationHandler({ 4 handleNotification: async () => ({ 5 shouldShowAlert: true, 6 shouldPlaySound: false, 7 shouldSetBadge: false, 8 }), 9}); 10 11export default function HomeScreen() { 12const [expoPushToken, setExpoPushToken] = useState(''); 13const [notification, setNotification] = useState(false); 14const notificationListener = useRef(); 15const responseListener = useRef(); 16 17useEffect(() => { 18 registerForPushNotificationsAsync().then(token => setExpoPushToken(token)); 19 20 notificationListener.current = Notifications.addNotificationReceivedListener(notification => { 21 setNotification(notification); 22 }); 23 24 responseListener.current = Notifications.addNotificationResponseReceivedListener(response => { 25 console.log(response); 26 }); 27 28 return () => { 29 Notifications.removeNotificationSubscription(notificationListener); 30 Notifications.removeNotificationSubscription(responseListener); 31 }; 32}, []); 33 34const user = useSelector(state => state.user); 35const {reminders} = user; 36const stringreminder = reminders.join(''); 37const FilteredItems = DummyItems.filter(function (dummy, index) { 38 if(stringreminder=="1"){ 39 return (dummy.title == "燃えるゴミ"); 40 }else if(stringreminder=="2"){ 41 return (dummy.title == "容器包装プラスチック"); 42 }else if(stringreminder==""){ 43 return (dummy.title == ""); 44 }else if(stringreminder=="12" || stringreminder=="21"){ 45 return (dummy.title == "燃えるゴミ" || dummy.title == "容器包装プラスチック"); 46 } 47 }); 48 49const items = FilteredItems.map((dummy, index) => { 50async function schedulePushNotification() { 51 await Notifications.scheduleNotificationAsync({ 52 content: { 53 title: '今日はゴミの日です!', 54 }, 55 trigger: { seconds: 2 }, 56 }); 57} 58 59async function registerForPushNotificationsAsync() { 60 let token; 61 if (Constants.isDevice) { 62 const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS); 63 let finalStatus = existingStatus; 64 if (existingStatus !== 'granted') { 65 const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS); 66 finalStatus = status; 67 } 68 if (finalStatus !== 'granted') { 69 alert('Failed to get push token for push notification!'); 70 return; 71 } 72 token = (await Notifications.getExpoPushTokenAsync()).data; 73 console.log(token); 74 } else { 75 alert('Must use physical device for Push Notifications'); 76 } 77 78 if (Platform.OS === 'android') { 79 Notifications.setNotificationChannelAsync('default', { 80 name: 'default', 81 importance: Notifications.AndroidImportance.MAX, 82 vibrationPattern: [0, 250, 250, 250], 83 lightColor: '#FF231F7C', 84 }); 85 } 86 87 return token; 88} 89 90 return( 91 92//一部抜粋
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。