我正在构建一个应用程序,它会将最近的产品经销商列入用户当前位置。
在我的设备上测试iPhone 6& iPhone 4S我可以看到我的应用程序没有获取该位置的权限,但是当我进入设置时,我无法看到列出的测试应用程序以授予其权限。
这是由于应用程序的安装方式"运行"通过Appcelerator Studio?我该如何授予测试应用程序权限?
我的代码是:
function getCurrentPhoneLocation(callback)
{
Titanium.API.info("get phone location " + Ti.Geolocation.locationServicesEnabled);
if(Ti.Geolocation.locationServicesEnabled)
{
Titanium.API.info("GPS permissions: " + Ti.Geolocation.locationServicesAuthorization + " (" + Ti.Geolocation.AUTHORIZATION_ALWAYS + " | " + Ti.Geolocation.AUTHORIZATION_AUTHORIZED + " | " + Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE + ")");
if (Ti.Geolocation.locationServicesAuthorization == Ti.Geolocation.AUTHORIZATION_ALWAYS || Ti.Geolocation.locationServicesAuthorization == Ti.Geolocation.AUTHORIZATION_AUTHORIZED || Ti.Geolocation.locationServicesAuthorization == Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)
{
Titanium.API.info("Got permissions - lets go!");
Ti.Geolocation.purpose = 'Get current location';
var currentPhoneLocation = {};
Ti.Geolocation.getCurrentPosition(function(e){
Titanium.API.info("from pos: " + JSON.stringify(e));
if(e.success === false) {
Ti.API.error('Error:' + e.error);
alert("Location is currently unavailable");
callback( false );
} else {
currentPhoneLocation.longitude = e.coords.longitude;
currentPhoneLocation.latitude = e.coords.latitude;
Ti.API.info("Returned Cords: " + JSON.stringify(currentPhoneLocation));
callback();
}
});
}
else
{
Titanium.API.info("No APP permission");
Titanium.UI.createAlertDialog({title:'Location Service', message:'Please grant this app permission to get your location.'}).show();
callback( false );
}
}
else
{
Titanium.API.info("No GPS available");
Titanium.UI.createAlertDialog({title:'Location Service', message:'Please turn on your location services.'}).show();
callback( false );
}
}
您可以看到我的跟踪代码显示Ti.Geolocation.locationServicesAuthorization正在返回' 0'。
[INFO] : get phone location true
[INFO] : GPS permissions: 0 (3 | 3 | 4)
[INFO] : No APP permission
[INFO] : Recieved location: false
答案 0 :(得分:1)
无论您如何安装,首选项的工作方式都相同。你还需要授权它。
但是,最新版本中的权限已经发生了很多变化,我建议您查看文档以正确设置它。您可以找到example app on GitHub
检查是否已授予的最佳方式是:
Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS);
另外,我建议提取位置。虚假实际上是由你提供的。如果您授予应用程序权限(在设置中验证),则应该可以使用
Ti.GeoLocation.getCurrentPosition(callback(e){})