Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export async function registerForPushNotificationsAsync(token) {
- const { status: existingStatus } = await Permissions.getAsync(
- Permissions.NOTIFICATIONS
- );
- let finalStatus = existingStatus;
- // Only ask if permissions have not already been determined, for iOS.
- if (existingStatus !== 'granted') {
- const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
- finalStatus = status;
- }
- // Stop here if the user did not grant permissions
- if (finalStatus !== 'granted') {
- return;
- }
- // Get the push token that uniquely identifies this device
- let expoToken = await Notifications.getExpoPushTokenAsync();
- // Post new push token to backend for user
- return axios({
- method: 'POST',
- url: `${str.ROOT_URL}/account/push/`,
- headers: {
- Authorization: `Token ${token}`
- },
- data: {
- "token": expoToken,
- "status": finalStatus
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement