Push Notifications Permissions


#1

Hey Guys, i use expo 22

No matter how I decide whether to allow it or not. he always jumps into this part:

if (status! ==' granted') {
    alert (' no')
    return;
  }

than i tried the code from the website:

import { Permissions, Notifications } from 'expo';
import Api from './api';

export default 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;
  }

  // Get the token that uniquely identifies this device
  let token = await Notifications.getExpoPushTokenAsync();
  alert('api')
  Api.patchUser({pushToken: token});
};

but the same… what can i do?


#2

if I let the token set the token anyway:

{
    "data": {
        "status": "error",
        "message": "The recipient \"ExponentPushToken[XAJDzDO9O2i3EtTtIyQTrx]\" isn't associated with any device",
        "details": {
            "error": "DeviceNotRegistered"
        }
    }
}

#3

This device has rejected giving permissions to send notifications. You need to open the Settings for the app (manually like a non-developer would) and enable notifications. This is how mobile (specifically iOS) works.


#4

no, it dosent working this way. I did this before.

i get this

{
    "data": {
        "status": "error",
        "message": "The recipient \"ExponentPushToken[XAJDzDO9O2i3EtTtIyQTrx]\" isn't associated with any device",
        "details": {
            "error": "DeviceNotRegistered"
        }
    }
}

#5

the finalStatus is undetermined


#6

Hi! Is this the exact code you’re running?

if (status! ==' granted') {
    alert (' no')
    return;
  }

(it’s from your first post)

If so, it looks like you have an extra space in the string you’re comparing to which will fail.


#7

Hey… no i tried some other code… everytime when ich log the status, it is ‘undetermined’. I tried more than one simulators, and do it manualy on.

So when i have a EXPO PUSH TOKEN, than i cant send push notifications too.


#8

I think I experienced the same bug:

On a real android device it works very well, but on iOS simulator the status returned by Permissions.getAsync(Permissions.NOTIFICATIONS) or Permissions.askAsync(Permissions.NOTIFICATIONS) is always undetermined, even after I approved the permission.

You can see the code here:

if you run the app on iOS, look at the console (redux logger is configured) you will see that status dispatched with the actionSET_NOTIFICATION_ASKED_PERMISSION is undetermined.


#9

Simulators don’t support push notifications, unfortunately. When testing push notifs, make sure to use a physical device.