Tag: cllocationmanager

iOS版。 CLLocationManager只在didUpdateLocations中接收位置更新一次

我有以下代码来获取位置更新(iOS 7): import UIKit import CoreLocation class FirstViewController: UIViewController, CLLocationManagerDelegate { var locationManager: CLLocationManager! override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } @IBAction func startTracking(sender : AnyObject) { NSLog("Start tracking") if (locationManager == nil) { locationManager = CLLocationManager() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation locationManager.distanceFilter = kCLDistanceFilterNone locationManager.pausesLocationUpdatesAutomatically = false } […]

禁用allowBackgroundLocationUpdates(CLLocationManager)在启用后不起作用

我的应用程序与连续的后台位置更新。 当然,它有所有的权限和其他的东西 allowsBackgroundLocationUpdates = true 最初,我想在后台使用NSProcessInfoPowerStateDidChange通知对NSProcessInfoPowerStateDidChange更改做出反应 。 并禁用allowsBackgroundLocationUpdates 停止更新位置,而无需调用stopUpdatingLocation 。 但是,我收到通知和设置后发现 allowsBackgroundLocationUpdates = false 在后台应用程序正在进行工作。 所以我走得更远,并确定, 禁用 allowsBackgroundLocationUpdates即使在最初设置为true 前景 ,根本不工作。 应用程序继续在后台工作。 苹果关于此事的文件 你使用这个属性来启用和禁用基于你的应用行为的行为 从CLLocationManager类, allowsBackgroundLocationUpdates属性的描述 将UIBackgroundModes设置为包含Info.plist中的“位置”时,只要调用-startUpdatingLocation以在后台继续,就必须在运行时将此属性设置为YES。 将此属性重置为NO相当于从UIBackgroundMode值中省略“位置”。 显示我提到的行为的简单项目在GitHub上。 所以这个问题,这是财产的故意行为吗?

用户的位置和电池的消耗

我正在研究侧重于build筑物(校园)中的行人的iOS应用程序。 我已经开发了一个足够好的(我相信)用户的位置更新,但是,我想任何人比我更专家给我一些提示,build议准确的位置,电池的问题等。此外,是否有可能停止位置更新和n秒后再次启动? 是我为了节能而做的一个想法。 目前,应用程序正在检测当前位置,但蓝点(用户)仍在移动,我不喜欢这样。 有什么可以做的? 以下是我的didUpdateToLocation方法: 应用程序正在从一个文件(存储在设备上)读取build筑物的信息 – (void)viewDidLoad{ [super viewDidLoad]; if ([self checkForInternet]) { _locationManager = [[CLLocationManager alloc] init]; _locationManager.delegate = self; _locationManager.distanceFilter = 10.0f; _locationManager.desiredAccuracy = 20.0f; [_locationManager startUpdatingLocation]; } } – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (newLocation.horizontalAccuracy > manager.desiredAccuracy) return; [self.mapView removeAnnotations:listOfAnn]; [listOfAnn removeAllObjects]; if ([manager locationServicesEnabled]) { for […]

iOS 8 – 无法获取当前位置,错误域= kCLErrorDomain代码= 0

我有问题得到我的当前位置。 我仍然收到错误: Error Domain=kCLErrorDomain Code=0 "The operation couldn't be completed. (kCLErrorDomain error 0.)" 我已经做了我在这里find的所有东西: 重置iOS模拟器中的内容和设置(模拟器中的地图应用程序显示正确的位置)。 在Xcode的产品>计划>编辑我未标记的允许位置模拟(当我标记它,它模拟例如伦敦)。 我已经添加NSLocationWhenInUseUsageDescription Info.plist文件在我的项目(应用程序要求的位置的权限,我可以看到他们在设置在iOS模拟器)。 我打开了Wi-Fi连接(就像我说的位置服务在Safari,地图,甚至在iOS模拟器中的地图一样正常工作)。 -(void)viewDidLoad { [super viewDidLoad]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; if(IS_OS_8_OR_LATER){ NSUInteger code = [CLLocationManager authorizationStatus]; if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) { if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) { [self.locationManager requestWhenInUseAuthorization]; } else { NSLog(@"Info.plist […]

重大的位置变化至less不会每15分钟触发一次

根据苹果文档,重要的位置变化应该至less每15分钟更新位置。 当我明显移动时,确实会收到更新,但在设备静止时不会收到更新。 你有什么更新的经验? 他们至less每15分钟来一次吗? 如果GPS级精度对您的应用程序不是至关重要的,并且您不需要连续跟踪,则可以使用重大更改位置服务。 正确使用重大更改位置服务至关重要,因为它至less每隔15分钟就会唤醒系统和应用程序,即使没有发生位置更改,也会持续运行,直到您停止。

监视重要位置更改的iOS应用程序是否可以在设备重启时重新启动?

从核心位置文档 : 您在位置pipe理器中注册的地区会在您的应用程序启动之间持续存在。 如果在应用程序未运行时发生区域交叉,系统会自动在后台唤醒应用程序(或重新启动),以便处理事件。 重新启动时,先前configuration的所有区域都可在您创build的任何位置pipe理器对象的monitoredRegions属性中使用。 不幸的是,目前还不清楚这个应用程序在设备重新启动后是否会重新启动,以响应区域更改。 即使在设备重新启动之后,监视后台重大位置变化的iOS应用是否会重新启动?

CLLocationManager kCLErrorDomain代码?

使用iBeacon和CoreLocation我收到以下错误: 错误域= kCLErrorDomain代码= 16“操作无法完成(kCLErrorDomain错误16.) 除非我错过了它,否则对于每个错误代码的含义,Apple似乎都没有明确的参考。 任何人都可以解释这个错误代码? 错误来自: – (void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion: (CLBeaconRegion *)region withError:(NSError *)error{ NSLog(@"%@", error); } – (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error{ NSLog(@"%@", error); }

CLLocationManager不能获取城市名称

我正在尝试使用以下代码使用CLLocationManager获取当前的城市和国家 – #pragma mark – Core Location Delegate Methods – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init]; [reverseGeocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) { NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!"); if (error){ NSLog(@"Geocode failed with error: %@", error); return; } NSLog(@"Received placemarks: %@", placemarks); CLPlacemark *myPlacemark = [placemarks objectAtIndex:0]; NSString *countryCode […]

为“超本地”应用程序获取用户位置(也处于死亡状态)的适当方式

要求 –我build立一个hyperlocal的应用程序,将提供基于他的位置的用户提供。 当在应用程序中,我可以得到他的当前位置,并相应地显示优惠,但我现在需要的是基于他的位置发送推送通知给用户。 所以我想找出用户的位置,并根据他的位置发送优惠。 我已经阅读苹果文档的重大改变定位服务,但这个答案是说,它不会工作,一旦应用程序被杀害。 我也读了关于跟踪用户的位置,但这不适合我的工作。 我没有得到超过5个更新的背景。 我当前在viewDidLoad代码 – if (self.locationManager == nil) { self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self.locationManager.delegate = self; self.locationManager.allowsBackgroundLocationUpdates = true; self.locationManager.pausesLocationUpdatesAutomatically = false; if ([CLLocationManager authorizationStatus] != AVAuthorizationStatusAuthorized) { [self.locationManager requestAlwaysAuthorization]; } } [self.locationManager startUpdatingLocation]; 而我的委托方法看起来像这样 – -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) { […]

我可以使用Xcode模拟器testing显着变化吗?

我想知道是否可以在Xcode模拟器中testing重大更改位置服务(startMonitoringSignificantLocationChanges方法),还是只能在实际设备中使用。 注意,我已经在模拟器中试过了,但是它不起作用,但是我不确定这是否仅仅是因为它在模拟器上不起作用,或者是因为我做了错误的事情。 谢谢