从1周起,如果我的gps应用程序无法检索信号(例如:在我家测试)我没有收到任何aler.我以这种方式设置了错误通知
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSString *errorType = (error.code == kCLErrorDenied) ?
@"Access Denied" : @"Errore sconosciuto";
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Errore recuperando la Location"
message:errorType
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
[alert release];
}
Run Code Online (Sandbox Code Playgroud)
为什么应用程序不检索数据,并没有显示警报弹出窗口?
iphone uialertview iphone-sdk-3.0 cllocationmanager didfailwitherror
这是我在AppDelegate类中的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = 1000; // 1 Km
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)
这是我在AppDelegate类中的委托方法
//This is the delegate method for CoreLocation
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
//printf("AppDelegate latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
Run Code Online (Sandbox Code Playgroud)
它工作在3.0,3.1,3.1.3,但它不适用于4.0模拟器和设备.
是什么原因 ?
IOS4最近推出了为特定应用启用/禁用位置服务的可能性.
我需要检测是否为MY应用程序启用/禁用了此设置.
首先我尝试过:
if ([CLLocationManager locationServicesEnabled])
{
....
}
Run Code Online (Sandbox Code Playgroud)
但是,这指的是全局位置服务,而不是特定的应用程序设置.
其次我试过用
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
...
}
Run Code Online (Sandbox Code Playgroud)
它可以工作但是在服务应用程序设置被禁用的情况下被调用,在其他情况下,例如,如果某个度量由于某些原因而失败.
我需要一个代码来检测是否允许我的应用程序使用位置服务.
我怎样才能实现这一目标?
感谢您的支持
该文件说,可监测的区域数量有限 -
(void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy
Run Code Online (Sandbox Code Playgroud)
但我找不到那个限制,有人知道吗?
我有一个应用程序,围绕设备的GPS和来自它的信息.重要的是,位置数据必须准确并且是最新的.我知道该设备受到GPS和GPS限制的限制,但我想知道我是否可以采取任何措施来调整/改善iPhone GPS的性能,特别是在速度区域.由于位置更新滞后于设备实时位置约3-5秒,因此位置管理器报告的速度也远远落后于实时值.就我而言,这太长了.我知道可能没有什么我可以做的,但有没有人在提高iPhone GPS的响应能力方面有任何成功?每一点都有所作为.
编辑1:
正如Apple建议的那样,我的位置管理器位于单件类中.
在SingletonDataController.m中:
static CLLocationManager* locationManager;
locationManager = [CLLocationManager new];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.headingFilter = kCLHeadingFilterNone;
if(([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) || ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateFull)) {
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
} else {
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
[sharedSingleton setLocationManager:locationManager];
[locationManager release];
Run Code Online (Sandbox Code Playgroud)
在MapView.m内部(实际使用位置管理器):
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {
//setup
[SingletonDataController sharedSingleton].locationManager.delegate = self;
//more setup
}
- (void)batteryChanged {
if(([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) || ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateFull)) {
[SingletonDataController sharedSingleton].locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
} else { …Run Code Online (Sandbox Code Playgroud) 我提交了一个应用程序,它以用户选择的固定间隔(5分钟,10分钟,30分钟,1小时)跟踪用户的位置(并将其发送到服务器).该应用程序也应该在后台工作(发送请求),我已将其声明为UIBackgroundMode = location.我可以在后台以固定的间隔发送请求.Apple拒绝了它,建议如下:
我们发现您的应用使用后台模式,但不包含要求该模式持续运行的功能.此行为不符合App Store审查指南.
我们注意到您的应用程序在Info.plist中的UIBackgroundModes键中声明了对位置的支持,但不包括需要持久位置的功能.
在应用程序处于后台时添加需要持续使用实时位置更新的功能或从UIBackgroundModes键中删除"位置"设置是合适的.如果您的应用程序不需要持久的实时位置更新,我们建议您使用重要更改位置服务或区域监控位置服务.
有关这些选项的更多信息,请参阅位置感知编程指南中的"启动重要更改位置服务"和"监控基于形状的区域"部分.
如果您选择添加使用位置背景模式的功能,请在您的应用程序说明中包含以下电池使用免责声明:
"继续使用GPS在后台运行会大大降低电池寿命."
如果我更改了重要的位置更改并UIBackgroundMode从中删除了密钥Info.plist,则应用程序将在后台被杀死,并且只有在事件发生时才会唤醒.但是我必须每隔5分钟将请求发送到服务器,并且我的应用程序在后台被杀死(假设用户没有移动,事件不是trigger = no请求被发送到服务器).
相同的代码,我假设设备实际上是因某种原因更新了位置两次,即使我只调用一次startUpdatingLocation()并在didUpdateLocations中运行一些stopUpdatingLocations()
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
manager.stopUpdatingLocation()
let loc: CLLocation = locations[locations.count - 1]
let id = 0
let type = 0
let number = 0
createNewDataPoint(id, loc: loc, type: type, number: number)
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,createNewDataPoint被调用两次,创建2个新数据点.它只在模拟器中发生一次,所以我假设它与实际设备和GPS有关,因为模拟器伪造了它的位置.
startUpdatingLocation()只在我的代码中一次,在一个按钮上.基本上,你单击按钮,去go manager.startUpdatingLocations(),didUpdateLocations在模拟器上点击一次,在设备上点击两次(相同的坐标),它创建2个新的数据点.
提及任何相关内容的唯一其他代码是设置准确性,过滤器,授权请求以及前面提到的startUpdatingLocation().有什么我可以做的,以确保我没有创建两倍于必要的数据点?
当GPS进入一个确定的区域时,我的所有地理围栏都会触发,起初我认为这是因为半径,但是即使在减半之后我也遇到了同样的问题.
import UIKit
import CoreLocation
class itemDesc {
var title: String
var coordinate: CLLocationCoordinate2D
var regionRadius: CLLocationDistance
var location: String
var type: String
init(title: String, coordinate: CLLocationCoordinate2D, regionRadius: CLLocationDistance, location: String, type: String) {
self.title = title
self.coordinate = coordinate
self.regionRadius = regionRadius
self.location = location
self.type = type
}
}
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
setupData()
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个简单的方法,它被馈送CLLocationDegrees并返回一个CLPlacemark.看看Apple的文档,这似乎是一项简单的任务.
以下是我放入游乐场的内容:
import CoreLocation
// this is necessary for async code in a playground
import PlaygroundSupport
// this is necessary for async code in a playground
PlaygroundPage.current.needsIndefiniteExecution = true
func geocode(latitude: CLLocationDegrees, longitude: CLLocationDegrees) -> CLPlacemark? {
let location = CLLocation(latitude: latitude, longitude: longitude)
let geocoder = CLGeocoder()
var placemark: CLPlacemark?
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
if error != nil {
print("something went horribly wrong")
}
if let placemarks = placemarks {
placemark = …Run Code Online (Sandbox Code Playgroud) ios ×6
iphone ×4
swift ×3
cllocation ×2
clregion ×1
device ×1
gps ×1
performance ×1
regions ×1
uialertview ×1