Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. export async function registerForPushNotificationsAsync(token) {
  2.  
  3. const { status: existingStatus } = await Permissions.getAsync(
  4. Permissions.NOTIFICATIONS
  5. );
  6. let finalStatus = existingStatus;
  7.  
  8. // Only ask if permissions have not already been determined, for iOS.
  9. if (existingStatus !== 'granted') {
  10. const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
  11. finalStatus = status;
  12. }
  13.  
  14. // Stop here if the user did not grant permissions
  15. if (finalStatus !== 'granted') {
  16. return;
  17. }
  18.  
  19. // Get the push token that uniquely identifies this device
  20. let expoToken = await Notifications.getExpoPushTokenAsync();
  21.  
  22. // Post new push token to backend for user
  23. return axios({
  24. method: 'POST',
  25. url: `${str.ROOT_URL}/account/push/`,
  26. headers: {
  27. Authorization: `Token ${token}`
  28. },
  29. data: {
  30. "token": expoToken,
  31. "status": finalStatus
  32. }
  33. });
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement