diff --git a/lib/notifications.js b/lib/notifications.js index 2353d59..76023c1 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -1,3 +1,4 @@ +import { Platform } from 'react-native' import {tempReminderObservable, periodReminderObservable} from '../local-storage' import Notification from 'react-native-push-notification' import Moment from 'moment' @@ -9,7 +10,10 @@ import nothingChanged from '../db/db-unchanged' export default function setupNotifications(navigate) { Notification.configure({ onNotification: (notification) => { - if (notification.data.id === '11' || notification.id === '1') { + if (Platform.OS === "ios" && notification.data && notification.data.id === '11') { + navigate('TemperatureEditView') + } + else if (Platform.OS === "android" && notification.id === '1') { navigate('TemperatureEditView') } else { navigate('Home') @@ -18,7 +22,11 @@ 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() @@ -42,14 +50,22 @@ 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() })