首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有仅在iOS上询问权限的弹出窗口,未确定权限,react-native-community/地理位置

没有仅在iOS上询问权限的弹出窗口,未确定权限,react-native-community/地理位置
EN

Stack Overflow用户
提问于 2020-02-18 18:03:54
回答 1查看 529关注 0票数 1

我使用react-native-community/geolocation来检查用户位置。只有在安卓系统中才能正常工作。位置在启动时使用,因此android中的弹出消息在启动时被提示。在iOS上,我没有弹出请求许可的窗口。

为了检查权限,我安装了react-native-location I,我的测试代码返回'notDetermined‘

我的代码:

代码语言:javascript
复制
import Geolocation from '@react-native-community/geolocation';
import RNLocation, {getCurrentPermission} from 'react-native-location';
...
if(Platform.OS === 'ios'){
            Geolocation.requestAuthorization(); 
            const locationConfig = {authorizationLevel: "whenInUse"}; //try "always" too
            Geolocation.setRNConfiguration(locationConfig);
}
...
RNLocation.configure({
  distanceFilter: 1.0
});

RNLocation.getCurrentPermission().then(curPerr => {
           console.log(curPerr); //result notDetermined
});

RNLocation.requestPermission({
  ios: "whenInUse",
  android: {
    detail: "coarse"
  }
}).then(granted => {

    console.log('granted: ', granted); //it doesn't show it in the console!

    if (granted) {
        this.locationSubscription = RNLocation.subscribeToLocationUpdates(locations => {
        })
    }
  })

Info.plist

代码语言:javascript
复制
    <key>NSLocationAlwaysUsageDescription</key>
    <string>We use your location...</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>We use your location...</string>    
    <key>NSLocationWhenInUseUsageDescription </key>
    <string>We use your location...</string>
...
<key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>location</string>
    </array>
EN

Stack Overflow用户

发布于 2020-03-06 16:53:50

我确实像你一样写过Info.plist文件,也遇到过同样的情况。在我的例子中,我删除了第一个和第二个选项,只保留了第三个选项,然后它就起作用了。

代码语言:javascript
复制
<key>NSLocationWhenInUseUsageDescription</key>
<string>We use your location...</string>

ios版本是12。我不是很确定,但这个Q&A与您的问题相关,可能会有所帮助。

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

https://stackoverflow.com/questions/60278279

复制
相关文章

相似问题

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