diff --git a/lib/notifications.js b/lib/notifications.js index 76023c1..38cb3a4 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -1,4 +1,3 @@ -import { Platform } from 'react-native' import {tempReminderObservable, periodReminderObservable} from '../local-storage' import Notification from 'react-native-push-notification' import Moment from 'moment' @@ -10,10 +9,8 @@ import nothingChanged from '../db/db-unchanged' export default function setupNotifications(navigate) { Notification.configure({ onNotification: (notification) => { - if (Platform.OS === "ios" && notification.data && notification.data.id === '11') { - navigate('TemperatureEditView') - } - else if (Platform.OS === "android" && notification.id === '1') { + // https://github.com/zo0r/react-native-push-notification/issues/966#issuecomment-479069106 + if (notification.data?.id === '1' || notification.id === '1') { navigate('TemperatureEditView') } else { navigate('Home') @@ -22,11 +19,7 @@ export default function setupNotifications(navigate) { }) tempReminderObservable(reminder => { - if (Platform.OS === "ios") { - Notification.cancelLocalNotifications({id: '11'}) - } else { Notification.cancelLocalNotifications({id: '1'}) - } if (reminder.enabled) { const [hours, minutes] = reminder.time.split(':') let target = new Moment() @@ -40,7 +33,7 @@ export default function setupNotifications(navigate) { Notification.localNotificationSchedule({ id: '1', - userInfo: { id: '11' }, + userInfo: { id: '1' }, message: labels.tempReminder.notification, date: target.toDate(), vibrate: false, @@ -50,22 +43,14 @@ export default function setupNotifications(navigate) { }, false) periodReminderObservable(reminder => { - if (Platform.OS === "ios") { - Notification.cancelLocalNotifications({id: '22'}) - } else { Notification.cancelLocalNotifications({id: '2'}) - } if (reminder.enabled) setupPeriodReminder() }, false) getBleedingDaysSortedByDate().addListener((_, changes) => { // the listener fires on setup, so we check if there were actually any changes if (nothingChanged(changes)) return - if (Platform.OS === "ios") { - Notification.cancelLocalNotifications({id: '22'}) - } else { Notification.cancelLocalNotifications({id: '2'}) - } if (periodReminderObservable.value.enabled) setupPeriodReminder() }) @@ -88,7 +73,7 @@ function setupPeriodReminder() { Notification.localNotificationSchedule({ id: '2', - userInfo: { id: '22' }, + userInfo: { id: '2' }, message: labels.periodReminder.notification(daysToEndOfPrediction), date: reminderDate.toDate(), vibrate: false