Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   registerForPushNotificationsAsync = async () => {
  2.     if (Constants.isDevice) {
  3.       const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
  4.       let finalStatus = existingStatus;
  5.      
  6.       if (existingStatus !== 'granted') {
  7.         const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
  8.         finalStatus = status;
  9.       }
  10.  
  11.       if (finalStatus !== 'granted') {
  12.         alert('Failed to get push token for push notification!');
  13.         return;
  14.       }
  15.       token = await Notifications.getExpoPushTokenAsync();
  16.       console.log(`token: ${token}`);
  17.       this.setState({ expoPushToken: token });
  18.     } else {
  19.       alert('Must use physical device for Push Notifications');
  20.     }
  21.     alert(token)
  22.     if (Platform.OS === 'android') {
  23.       Notifications.createChannelAndroidAsync('default', {
  24.         name: 'default',
  25.         sound: true,
  26.         priority: 'max',
  27.         vibrate: [0, 250, 250, 250],
  28.       });
  29.     }
  30.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement