【问题标题】:Fix Cordova Geolocation Ask for Location Message修复 Cordova Geolocation 请求位置消息
【发布时间】:2015-05-07 14:50:37
【问题描述】:

有没有人有使用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

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

-谢谢

【问题讨论】:

  • 你安装了地理定位插件吗?
  • 看到这个answer

标签: ios xcode cordova geolocation message


【解决方案1】:

除了DaveAlden 的回答之外,我不得不删除旧版本的地理定位插件并添加新的。然后我不得不删除/添加 Cordova iOS 平台。只有这样我才能成功地将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>

有关NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescriptionNSLocationUsageDescription 的详细信息,请参阅此iOS Developer Library link

Location permission alert on iPhone with Cordova 可能是重复的。

【讨论】:

    【解决方案2】:

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

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

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

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

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

    【讨论】:

    猜你喜欢
    • 2014-10-19
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多