我正在构建一个应用程序,它将列出离用户当前位置最近的产品经销商。
在我的设备 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