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});
};
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.
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.
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.