【问题标题】:No popup asking permission only on iOS, permission not determined, react-native-community/geolocation仅在 iOS 上没有弹出询问权限,未确定权限,react-native-community/geolocation
【发布时间】:2020-02-18 10:03:54
【问题描述】:

我使用 react-native-community/geolocation 来检查用户位置。一切都只能在android中正常工作。位置在启动时使用,因此在启动时会在 android 弹出消息中提示。 在 iOS 上,我没有弹出请求权限。

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

我的代码:

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

    <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>

【问题讨论】:

    标签: react-native


    【解决方案1】:

    我确实像您一样编写了 Info.plist 文件并且遇到了相同的情况。 就我而言,我删除了第一个和第二个选项,只保留了第三个选项,然后它就起作用了。

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>We use your location...</string>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 2013-05-21
      • 2021-08-09
      • 1970-01-01
      • 2022-11-05
      相关资源
      最近更新 更多