仅在 iOS 上没有弹出询问权限,未确定权限,react-native-community/geolocation
Posted
技术标签:
【中文标题】仅在 iOS 上没有弹出询问权限,未确定权限,react-native-community/geolocation【英文标题】:No popup asking permission only on iOS, permission not determined, 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>
【问题讨论】:
【参考方案1】:我确实像您一样编写了 Info.plist 文件并且遇到了相同的情况。 就我而言,我删除了第一个和第二个选项,只保留了第三个选项,然后它就起作用了。
<key>NSLocationWhenInUseUsageDescription</key>
<string>We use your location...</string>
ios版本为12。 我不太确定,但这个Q&A 与您的问题有关,可能会有所帮助。
【讨论】:
以上是关于仅在 iOS 上没有弹出询问权限,未确定权限,react-native-community/geolocation的主要内容,如果未能解决你的问题,请参考以下文章
Xamarin.iOS 应用在 iOS 14.0 中询问本地网络权限