Created
January 23, 2019 06:38
-
-
Save aloukissas/651f41cde13d9aa12aaa3cfb21c2affd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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