首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Permissions.askAsync(Permissions.NOTIFICATIONS)不工作React-native

Permissions.askAsync(Permissions.NOTIFICATIONS)不工作React-native
EN

Stack Overflow用户
提问于 2020-06-28 01:54:53
回答 1查看 421关注 0票数 2

我是第一次接触React-native。下面提到了依赖关系

代码语言:javascript
复制
 "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"
  }

这是我需要检查权限的部分,如果没有权限,我需要请求它。

代码语言:javascript
复制
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通知权限并尝试运行应用程序,它甚至不会请求权限,警报就会显示出来。知道哪里出了问题吗?

EN

回答 1

Stack Overflow用户

发布于 2021-01-20 11:49:41

我们一直在努力解决这个问题,因为它使得应用程序很难测试。这本身不是expo/react本身的问题,而是android的一个特性。

即使在两次安装之间,Android也会记住权限。因此,如果你安装了一次,并请求许可,然后卸载应用程序。随后出现权限对话框的尝试将不起作用。

我们必须在不同的设备上进行测试才能让它工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62613626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档