I am having an issue with Permissions.askAsync for notifications.
const status = await Permissions.askAsync(Permissions.NOTIFICATIONS)
When notification status is "undetermined" using Permissions.askAsync I expect to be presented with prompt dialog telling user to turn on notifications in order to continue. But, when I get status of the notifications with Permissions.getAsync, if it's not "granted" I use Permissions.askAsync but nothing is happening(not showing the dialog for notifications)
Environment below:
Target: iOS
Expo CLI 3.8.0 environment info:
System:
OS: macOS 10.14.6
Shell: 5.3 - /bin/zsh
Binaries:
Node: 12.13.1 - /usr/local/bin/node
npm: 6.12.1 - /usr/local/bin/npm
Watchman: 4.7.0 - /usr/local/bin/watchman
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild
npmPackages:
expo: ^35.0.0 => 35.0.1
react: 16.11.0 => 16.11.0
react-native: https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz => 0.59.8
react-navigation: ^3.11.0 => 3.12.1
npmGlobalPackages:
expo-cli: 3.8.0
Sample below:
import * as Permissions from "expo-permissions"
componentDidMount(){
this.checkPushNotificationState()
}
checkPushNotificationState = async () => {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
)
if (existingStatus !== "granted") {
const status = await Permissions.askAsync(Permissions.NOTIFICATIONS)
statusNotifications = status.status
}
}
use app-setting link to open setting for manual permission because ios do not allow us to give permission from prompt if user reject permission
Linking.openURL('app-settings:')
like this
import React, { Component } from "react";
import { Text, StyleSheet, View, Linking, Alert } from "react-native";
import * as Permissions from "expo-permissions";
export default class App extends Component {
componentDidMount() {
this.checkPushNotificationState();
}
checkPushNotificationState = async () => {
let { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
if (existingStatus !== "granted") {
const status = await Permissions.askAsync(Permissions.NOTIFICATIONS);
existingStatus = status.status;
}
if (existingStatus !== "granted") {
Alert.alert(
"No Notification Permission",
"please goto setting and on notification permission manual",
[
{ text: "cancel", onPress: () => console.log("cancel") },
{ text: "Allow", onPress: () => Linking.openURL("app-settings:") },
],
{ cancelable: false }
);
return;
}
};
Note: you should use double permission for The Right Way to Ask Users for Mobile Permissions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With