Skip to content

Commit

Permalink
FIX: Adding notification time
Browse files Browse the repository at this point in the history
  • Loading branch information
diogosilverio committed Feb 4, 2018
1 parent ee83f88 commit 343cca9
Showing 1 changed file with 41 additions and 26 deletions.
67 changes: 41 additions & 26 deletions utils/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}

}

0 comments on commit 343cca9

Please sign in to comment.