Dev*_*DOS 3 javascript iphone ios cordova-4
我正在研究一个cordova app我必须经过locate the user纬度和经度的东西。使用地理定位插件,它在 android 设备上运行良好,但它显示一个警报,要求用户在iOS. 当我使用模拟器时,我收到此警报消息:
Users/user/Library/Developer/CoreSimulator/Devices/783A2EFD-2976-448C-8E4E-841C985D337D/data/Containers/Bundle/Application/EFC846BB-4BA3-465C-BD44-575582E649FC/app_name.app/www/index.html would like to use your current location.
Run Code Online (Sandbox Code Playgroud)
我看到过这样的话题谈论这个问题:这个和这个但是提供的解决方案都不适合我。
这是cordova示例页面:
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />' +
'Accuracy: ' + position.coords.accuracy + '<br />' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
'Heading: ' + position.coords.heading + '<br />' +
'Speed: ' + position.coords.speed + '<br />' +
'Timestamp: ' + position.timestamp + '<br />';
}
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
</body>
Run Code Online (Sandbox Code Playgroud)
有什么方法可以更改警报的文本或禁用此警报?
-编辑 - -
我已经找到了问题的根源。我删除了地理定位插件并添加了几次,因为当我添加插件时,我没有找到与geolocation plugin其他插件名称相同的文件夹。甚至该cordova_plugin.js文件也不包含有关地理定位插件的任何数据。现在我再次安装了插件并且它可以工作。
与原始问题中的“编辑”相同,我必须删除旧版本的地理定位插件并添加新版本。然后我不得不删除/添加 Cordova iOS 平台。只有这样我NSLocationWhenInUseUsageDescription才能将DaveAlden添加到 .plist 文件中在他的回答中提到的那样成功地中。
首先,删除/添加地理定位插件:
cordova plugin rm org.apache.cordova.geolocation
cordova plugin add org.apache.cordova.geolocation
Run Code Online (Sandbox Code Playgroud)
二、移除/添加iOS平台:
cordova platform rm ios
cordova platform add ios
Run Code Online (Sandbox Code Playgroud)
最后,添加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>
Run Code Online (Sandbox Code Playgroud)
看到这个的iOS开发者库的链接有关的详细信息NSLocationWhenInUseUsageDescription与NSLocationAlwaysUsageDescription对比NSLocationUsageDescription。