Skip to content

Instantly share code, notes, and snippets.

@ShMcK
Created March 12, 2018 20:32
Show Gist options
  • Save ShMcK/26dbb2d7cc7d7155014b0163eb3daa2f to your computer and use it in GitHub Desktop.
Save ShMcK/26dbb2d7cc7d7155014b0163eb3daa2f to your computer and use it in GitHub Desktop.
Notification Permissions
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