[英]Error: One of the `NSLocation*UsageDescription` keys must be present in Info.plist to be able to use geolocation
When I want to test my app with Expo Go on iOS I get this error:当我想在 iOS 上使用 Expo Go 测试我的应用程序时,出现此错误:
[Unhandled promise rejection: Error: One of the `NSLocation*UsageDescription` keys must be present in Info.plist to be able to use geolocation.]
Stack trace:
node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:104:50 in promiseMethodWrapper
node_modules\expo-modules-core\build\NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
I added that configuration to info.plist, rebuilt the project, but I get the same error, I also reinstalled node packages, but it didn't change anything.我将该配置添加到 info.plist,重建了项目,但我得到了同样的错误,我还重新安装了节点包,但它没有改变任何东西。
package.json package.json
"dependencies": {
"@expo/vector-icons": "^12.0.0",
"expo": "~43.0.2",
"expo-location": "~13.0.4",
"expo-status-bar": "~1.1.0",
"expo-task-manager": "~10.0.3",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-paper": "4.9.2",
"react-native-web": "0.17.1",
"expo-splash-screen": "~0.13.5",
"expo-updates": "~0.10.13",
"react-native-gesture-handler": "~1.10.2",
"react-native-reanimated": "~2.2.0",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.8.0"
},
"devDependencies": {
"@babel/core": "^7.12.9"
}
My js code我的js代码
const { status } = await Location.requestForegroundPermissionsAsync();
if (status === "granted") {
const background = await Location.requestBackgroundPermissionsAsync();
if (background.status === "granted") {
await Location.startLocationUpdatesAsync(TASK_FETCH_LOCATION, {
activityType: Location.LocationActivityType.BestForNavigation,
showsBackgroundLocationIndicator: true,
accuracy: Location.Accuracy.BestForNavigation,
deferredUpdatesInterval: 3000,
deferredUpdatesDistance: 50,
showsBackgroundLocationIndicator: true,
}).then(() => {
Alert.alert("Turn on", null, [
{ text: "OK", onPress: () => console.log("listening gps") },
]);
});
}
}
app.json申请.json
"ios": {
"supportsTablet": true,
"infoPlist": {
"UIBackgroundModes": [
"location",
"fetch"
],
"NSLocationAlwaysAndWhenInUseUsageDescription": "Allows App to use location services in the foreground and background.",
"NSFaceIDUsageDescription": "Allows App to use Face ID for a simpler sign in."
}
}
You need to explicitly set these key-string pair inside of the Info.plist of your project.您需要在项目的 Info.plist 中显式设置这些键-字符串对。
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Your geolocation string</string>
my app.config looks like that:我的 app.config 看起来像这样:
{
"expo": {
...
"ios": {
"supportsTablet": true,
"infoPlist": {
"UIBackgroundModes": [
"location",
"fetch"
],
"NSLocationWhenInUseUsageDescription": "text",
"NSLocationAlwaysAndWhenInUseUsageDescription": "text",
"NSLocationAlwaysUsageDescription": "text"
}
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"permissions": [
"ACCESS_BACKGROUND_LOCATION"
]
},
...
}
}
But I am getting still the same warning you are getting.但是我仍然收到与您收到的警告相同的警告。 I also copied that code ( https://chafikgharbi.com/expo-location-tracking/ ) one by one, but still I am getting the warning und background is not working on my iphone.我还一一复制了该代码 ( https://chafikgharbi.com/expo-location-tracking/ ),但我仍然收到警告,背景在我的 iphone 上不工作。 Does someone have a hint?有人有提示吗? I really don't want to eject the expo app...我真的不想弹出 expo 应用程序...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.