Skip to content

Instantly share code, notes, and snippets.

@aloukissas
Created January 23, 2019 06:38
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/651f41cde13d9aa12aaa3cfb21c2affd to your computer and use it in GitHub Desktop.
Save aloukissas/651f41cde13d9aa12aaa3cfb21c2affd to your computer and use it in GitHub Desktop.
import { Permissions } from "expo";
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment