-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPushNotification.js
42 lines (36 loc) · 1.34 KB
/
PushNotification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Permissions, Notifications } from 'expo';
import { BASE_URL } from './Constants';
const PUSH_ENDPOINT = `${BASE_URL}/push-token`;
export async function registerForPushNotificationsAsync() {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== 'granted') {
// Android remote notification permissions are granted during the app
// install, so this will only ask on iOS
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== 'granted') {
return;
}
// Get the token that uniquely identifies this device
let expoPushToken = await Notifications.getExpoPushTokenAsync();
return expoPushToken;
// POST the token to your backend server from where you can retrieve it to send push notifications.
// return fetch(PUSH_ENDPOINT, {
// method: 'POST',
// headers: {
// Accept: 'application/json',
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify({
// token: expoPushToken,
// helpRequesterId: '',
// }),
// });
}