Created
March 12, 2018 20:32
-
-
Save ShMcK/26dbb2d7cc7d7155014b0163eb3daa2f to your computer and use it in GitHub Desktop.
Notification Permissions
This file contains hidden or 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' | |
export default async function verifyPushNotificationsPermissions() { | |
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 | |
} | |
if (finalStatus === 'undetermined') { | |
console.log('Cannot use push notifications on simulator') | |
} | |
// 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