【问题标题】:Permissions not working in react native Expo standalone app (build)权限在本机 Expo 独立应用程序(构建)中不起作用
【发布时间】:2018-08-30 08:39:57
【问题描述】:

我正在尝试在 react native expo 中获得位置权限,但未能这样做。 我搜索了很多,但找不到合适的解决方案。 位置权限的代码 sn-p 是:

 async componentDidMount(){
    try {
      const granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
        {
          'title': 'Location Permission',
          'message': 'Allow App to use location of your device.' 
                     
        }
      )
      if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        console.log("got")
        this.setState({show:false});
      } else {
        console.log("failed")
      }
    } catch (err) {
      console.log('error',err)
    }
    
    
  }

它显示以下错误:

错误 [错误:尝试使用权限 API,但宿主 Activity 未实现 PermissionAwareActivity。]

我正在使用

"世博": "^25.0.0", “反应”:“16.2.0”, "react-native": "https://github.com/expo/react-native/archive/sdk-25.0.0.tar.gz",

谢谢

【问题讨论】:

    标签: react-native permissions expo


    【解决方案1】:

    使用 Expo Permission API

    const { status } = await Expo.Permissions.askAsync(Expo.Permissions.LOCATION);
    
    if (status === 'granted') {
        const location = await Expo.Location.getCurrentPositionAsync({
          enableHighAccuracy: true,
        });
        return location;
    }
    

    【讨论】:

    • 感谢您的回复。我试过了,但无法获得权限
    • 在我的情况下条件是错误的
    • 很高兴它对您有所帮助
    猜你喜欢
    • 2017-12-09
    • 2020-05-11
    • 1970-01-01
    • 2019-12-23
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多