我是第一次接触React-native。下面提到了依赖关系
"dependencies": {
"@react-native-community/masked-view": "0.1.6",
"@react-navigation/drawer": "^5.8.2",
"@react-navigation/native": "^5.5.1",
"@react-navigation/stack": "^5.2.10",
"axios": "^0.19.2",
"expo": "37.0.8",
"expo-notifications": "^0.1.1",
"expo-permissions": "^8.1.0",
"expo-secure-store": "^8.1.0",
"ngrok": "^3.2.7",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-animatable": "^1.3.3",
"react-native-datepicker": "^1.7.2",
"react-native-elements": "^2.0.2",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "~1.7.0",
"react-native-safe-area-context": "0.7.3",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "~2.2.0",
"react-native-swipeout": "^2.3.6",
"react-native-vector-icons": "^6.6.0",
"react-native-web": "~0.11.7",
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0"
}这是我需要检查权限的部分,如果没有权限,我需要请求它。
import * as Permissions from "expo-permissions"
import { Notifications} from 'expo'
obtainNotificationPermission = async () => {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS)
if( existingStatus !== 'granted'){
const nextpermission = await Permissions.askAsync(Permissions.NOTIFICATIONS)
if(nextpermission.status !=='granted'){
Alert.alert('Permission not granted to show notifications')
}
}
}
presentLocalNotification = async (date) =>{
await this.obtainNotificationPermission();
Notifications.presentLocalNotificationAsync({title:'test',body: 'Reservation for'+date+'
requested',
android:{
sound: true,
vibrate: true
}
})
}如果我手动允许权限,我将收到通知。但是如果我没有给expo通知权限并尝试运行应用程序,它甚至不会请求权限,警报就会显示出来。知道哪里出了问题吗?
发布于 2021-01-20 11:49:41
我们一直在努力解决这个问题,因为它使得应用程序很难测试。这本身不是expo/react本身的问题,而是android的一个特性。
即使在两次安装之间,Android也会记住权限。因此,如果你安装了一次,并请求许可,然后卸载应用程序。随后出现权限对话框的尝试将不起作用。
我们必须在不同的设备上进行测试才能让它工作。
https://stackoverflow.com/questions/62613626
复制相似问题