Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- registerForPushNotificationsAsync = async () => {
- if (Constants.isDevice) {
- const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
- let finalStatus = existingStatus;
- if (existingStatus !== 'granted') {
- const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
- finalStatus = status;
- }
- if (finalStatus !== 'granted') {
- alert('Failed to get push token for push notification!');
- return;
- }
- token = await Notifications.getExpoPushTokenAsync();
- console.log(`token: ${token}`);
- this.setState({ expoPushToken: token });
- } else {
- alert('Must use physical device for Push Notifications');
- }
- alert(token)
- if (Platform.OS === 'android') {
- Notifications.createChannelAndroidAsync('default', {
- name: 'default',
- sound: true,
- priority: 'max',
- vibrate: [0, 250, 250, 250],
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement