xcode 修复 Cordova Geolocation 询问位置消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28891339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:46:26  来源:igfitidea点击:

Fix Cordova Geolocation Ask for Location Message

iosxcodecordovageolocationmessage

提问by pavbagel

Does anyone have experience using cordova, html and know how to fix this geolocation message issue for iOS? I just want the message to say the app name followed by the line, "would like to use your current location."

有没有人有使用cordova、html的经验并且知道如何为iOS解决这个地理定位消息问题?我只是想让消息说出应用程序名称,然后是“想要使用您当前的位置”。

Current Geolocation Message:

当前地理位置消息:

///Users/kklsndksjladn/Library/Developer/CoreSimulator/Devices/FAF7EE4C-40BA-430A-80D5-5C84B07D970D/data/Containers/Bundle/Application/DAE305B6-C6DD-438B-B4D7-9B183A8B2D97/HelpME.app/www/index.html

///Users/kklsndksjladn/Library/Developer/CoreSimulator/Devices/FAF7EE4C-40BA-430A-80D5-5C84B07D970D/data/Containers/Bundle/Application/DAE305B6-C6DD-438B-B4D7/www-8Bindex.app.html .html

I've tried various solutions from stack overflow and other websites. I implemented the navigator.geolocation.getCurrentPosition(onSuccess, onError);code, included my cordova.js file in every html page, made sure <script> src=cordova.js</script>appears first in my index.html page, included the geolocation tag in my config.xml file and tried playing around with my plist. Someone please help!!!!

我已经尝试了堆栈溢出和其他网站的各种解决方案。我实现了 navigator.geolocation.getCurrentPosition(onSuccess, onError);代码,在每个 html 页面中包含了我的 cordova.js 文件,确保<script> src=cordova.js</script>首先出现在我的 index.html 页面中,在我的 config.xml 文件中包含了地理位置标签,并尝试使用我的 plist。有人请帮忙!!!!

-Thanks

-谢谢

回答by trailing slash

In addition to the answer from DaveAlden, I had to remove the old version of the geolocation plugin and add the new one. Then I had to remove/add the Cordova iOS platform. Only then could I add NSLocationWhenInUseUsageDescriptionto the .plist file with success.

除了DaveAlden的回答之外,我还必须删除旧版本的地理定位插件并添加新版本。然后我不得不删除/添加 Cordova iOS 平台。只有这样我NSLocationWhenInUseUsageDescription才能成功添加到 .plist 文件中。

First, remove/add the geolocation plugin:

首先,删除/添加地理定位插件:

cordova plugin rm org.apache.cordova.geolocation
cordova plugin add org.apache.cordova.geolocation

Second, remove/add the iOS platform:

二、移除/添加iOS平台:

cordova platform rm ios
cordova platform add ios

Last, add NSLocationWhenInUseUsageDescriptionto the .plist. Open /platforms/ios/{project}/{project}-Info.plistand add the following:

最后,添加NSLocationWhenInUseUsageDescription到 .plist。打开/platforms/ios/{project}/{project}-Info.plist并添加以下内容:

<key>NSLocationWhenInUseUsageDescription</key>
<string>[App Name] would like to access your location when running and displayed.</string>

See this iOS Developer Library linkfor detailed information regarding NSLocationWhenInUseUsageDescriptionversus NSLocationAlwaysUsageDescriptionversus NSLocationUsageDescription.

看到这个的iOS开发者库的链接有关的详细信息NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription对比NSLocationUsageDescription

Location permission alert on iPhone with Cordovais a possible duplicate.

带有 Cordova 的 iPhone 上的位置权限警报可能是重复的。

回答by DaveAlden

To customise the iOS location permission request message, you need to add a property to your project's .plist.

要自定义 iOS 位置权限请求消息,您需要向项目的 .plist 添加一个属性。

If your app requests permission to use location in the background, you want the following key (set the string value to anything you like):

如果您的应用请求在后台使用位置的权限,您需要以下键(将字符串值设置为您喜欢的任何值):

<key>NSLocationAlwaysUsageDescription</key>
<string>My app requires constant access to your location, even when the screen is off.</string>

If your app only uses location while in the foreground, then add the following key:

如果您的应用仅在前台使用位置,请添加以下键:

<key>NSLocationWhenInUseUsageDescription</key>
<string>My app requires access to your location when the screen is on and the app is displayed.</string>