Skip to content

Commit

Permalink
FEATURE: Notifications
Browse files Browse the repository at this point in the history
App throws notifications if user is more than 24hours without playing.
  • Loading branch information
diogosilverio committed Feb 4, 2018
1 parent a6f5556 commit ee83f88
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import FlashStackNavigator from './components/navigators/FlashStackNavigator';

import reducers from './reducers';

import { prepareNotification } from './utils/notification';

export default class App extends Component {

render() {

const store = createStore(reducers);
prepareNotification();

return (
<Provider store={store}>
Expand Down
40 changes: 40 additions & 0 deletions utils/notification.js
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();
}

}

}

0 comments on commit ee83f88

Please sign in to comment.