-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App throws notifications if user is more than 24hours without playing.
- Loading branch information
1 parent
a6f5556
commit ee83f88
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Notifications, Permissions } from 'expo'; | ||
|
||
import { getScores } from '../services'; | ||
|
||
export async function prepareNotification() { | ||
const scores = await getScores(); | ||
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS); | ||
|
||
if (scores.length === 0) { | ||
//notificar logo | ||
} else { | ||
|
||
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 | ||
} | ||
}) | ||
} else { | ||
Notifications.cancelAllScheduledNotificationsAsync(); | ||
} | ||
|
||
} | ||
|
||
} |