gpt4 book ai didi

ios - 在 iOS 设备上测试定位服务

转载 作者:行者123 更新时间:2023-11-29 01:16:57 25 4
gpt4 key购买 nike

我正在构建一个应用程序,它将列出距离用户当前位置最近的产品经销商。

在我的设备 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

最佳答案

无论您如何安装,首选项都是一样的。您仍然需要授权它。

但是,在最新版本中,权限发生了很多变化,我建议查看文档以正确设置它。你可以找到一个 example app on GitHub

检查它是否已被授予的最佳方法是通过:

Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS);

此外,我建议获取位置。假的其实是你提供的。如果您授予应用程序权限(在设置中验证),这应该可以工作

Ti.GeoLocation.getCurrentPosition(callback(e){})

关于ios - 在 iOS 设备上测试定位服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35060694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com