From 343cca9236bf2731d77992288d926aecc191d106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Silv=C3=A9rio?= Date: Sun, 4 Feb 2018 00:47:00 -0200 Subject: [PATCH] FIX: Adding notification time --- utils/notification.js | 67 ++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/utils/notification.js b/utils/notification.js index f218380..4a9f605 100644 --- a/utils/notification.js +++ b/utils/notification.js @@ -6,35 +6,50 @@ export async function prepareNotification() { const scores = await getScores(); const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS); - if (scores.length === 0) { - //notificar logo - } else { + if (status === 'granted') { - scores.sort((a, b) => { - return b.date - a.date - }) - - const score = scores[0]; - - const _24hago = 24 * 60 * 60 * 1000; - const now = Date.now(); - const threshold = (now - _24hago) > score.date; - - if(threshold){ - Notifications.scheduleLocalNotificationAsync({ - title: 'Quiz time!', - body: "Improve your skills practicing every day!", - android: { - sound: true, - priority: 'max', - vibrate: true, - sticky: false - } - }) + if (scores.length === 0) { + //notificar logo } else { - Notifications.cancelAllScheduledNotificationsAsync(); - } + scores.sort((a, b) => { + return b.date - a.date + }) + + const score = scores[0]; + + const _24hago = 24 * 60 * 60 * 1000; + const now = Date.now(); + const threshold = (now - _24hago) > score.date; + + const time = new Date(); + time.setHours(time.getHours() + 1); + time.setMinutes(0); + time.setSeconds(0); + + if (threshold) { + Notifications.scheduleLocalNotificationAsync({ + title: 'Quiz time!', + body: "Improve your skills practicing every day!", + android: { + sound: true, + priority: 'max', + vibrate: true, + sticky: false + } + }, + { + time, + repeat: 'day' + } + ); + } else { + Notifications.cancelAllScheduledNotificationsAsync(); + } + + } + } else { + console.log(`Permission denied for Notifications: ${status}`); } } \ No newline at end of file