Skip to content

Instantly share code, notes, and snippets.

@aloukissas
Created January 23, 2019 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aloukissas/2369332c3a8c12887451081edffcbf85 to your computer and use it in GitHub Desktop.
Save aloukissas/2369332c3a8c12887451081edffcbf85 to your computer and use it in GitHub Desktop.
import { Notifications, Permissions } from "expo";
const PUSH_ENDPOINT = "https://your-push-server/push-token"
async function registerForPushNotificationsAsync() {
// Request permissions -- same as earlier
[...]
// Get the token that uniquely identifies this device
const token = await Notifications.getExpoPushTokenAsync();
// 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: "Content-Type": "application/json",
},
body: JSON.stringify({
token: {
value: token,
},
user: {
userId: "current_user_id",
},
}),
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment