修复cordova地理位置询问位置信息

有没有人有经验使用cordova,HTML和知道如何解决iOS的这个地理定位消息问题? 我只是想让消息说出应用程序名称,后面跟着“想要使用你当前的位置”。

当前的定位信息:

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

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

-谢谢

除了DaveAlden的回答,我不得不删除旧版本的地理位置插件,并添加新的。 然后,我不得不删除/添加cordovaiOS平台。 只有这样我才能成功添加NSLocationWhenInUseUsageDescription到.plist文件。

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

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

其次,删除/添加iOS平台:

 cordova platform rm ios cordova platform add ios 

最后,将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> 

请参阅此iOS开发人员库链接 ,了解有关NSLocationWhenInUseUsageDescription详细信息时使用使用说明与NSLocationAlwaysUsageDescriptionNSLocationUsageDescription

与cordovaiPhone上的位置权限提醒是可能的重复。

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

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

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

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

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