简体   繁体   English

ios7中的CLLocationManager停止工作

[英]CLLocationManager in ios7 stops working

My CLLocationManager starts when the user first enters the app. 我的CLLocationManager在用户第一次进入应用程序时启动。 I am initializing it like this: 我正在初始化它像这样:

self.locationManager = [[CLLocationManager alloc] init];
            self.locationManager.delegate = self;
            self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
            self.locationManager.distanceFilter = kDistanceFilter;
            self.locationManager.headingFilter = kHeadingFilter;

And I am using geofencing. 我正在使用地理围栏。

I have defined in my .plist the required background modes . 我在.plist中定义了required background modes

If I test the app in the simulator using a gpx file, it works fine. 如果我使用gpx文件在模拟器中测试应用程序,它可以正常工作。 So far, so good. 到现在为止还挺好。

However, I read in these two links: 但是,我读了这两个链接:

Start Location Manager in iOS 7 from background task 从后台任务启动iOS 7中的位置管理器

Background Location Services not working in iOS 7 后台位置服务在iOS 7中不起作用

That in iOS7 , when the location does not change for a couple of minutes then the CLLocation goes to sleep. iOS7 ,当位置没有改变几分钟然后CLLocation进入睡眠状态。

My question is that: 我的问题是:

I do not call didUpdateLocation at all, I only want the didEnterRegion , or didExitRegion . 我根本不调用didUpdateLocation ,我只想要didEnterRegiondidExitRegion Theoretically, will it work , even the app is killed or user Location has not changed in the last hour and then decides to move? 理论上,它会工作,甚至应用程序被杀死或用户位置在过去一小时内没有改变然后决定移动?

There are a few elements in your questions: 您的问题中有一些要素:

1- In order not to rehash what is in a previous answer, I would first look at my answer at this link. 1-为了不重复前一个答案中的内容,我首先会在这个链接上查看我的答案。 It will help you resolve around the core location updates stopping if the user stops moving and how you can modify that behaviour: iOS7 Core Location not updating 如果用户停止移动以及如何修改该行为,它将帮助您解决核心位置更新停止: iOS7核心位置未更新

2- If the user kills an app in iOS7 (by flicking it up in the app switcher), the app will not restart and as such neither your location updates nor region monitoring will restart after the phone is restarted. 2-如果用户在iOS7中杀死应用程序(通过在应用程序切换器中轻弹),应用程序将不会重新启动,因此在重新启动手机后,您的位置更新和区域监控都不会重新启动。 On the other hand, if the app is killed because of memory pressures, iOS will restart the app and relaunch your location updates and region monitoring in the background. 另一方面,如果应用程序因内存压力而被终止,iOS将重新启动应用程序并在后台重新启动位置更新和区域监控。 Also, if you reboot the phone, region monitoring will restart automatically. 此外,如果重新启动手机,区域监控将自动重启。 You obviously must have the background mode enabled. 你显然必须启用后台模式。

3- Now you are talking about regions in your questions so I am assuming you have implemented CLCircularRegion. 3-现在你在谈论你问题中的区域,所以我假设你已经实现了CLCircularRegion。 If not, that should be the first step and then "startMonitoringForRegion". 如果没有,那应该是第一步,然后是“startMonitoringForRegion”。 In your case, even if the user has stopped moving for a while and then started moving, the app will be awaken/delegate called when the app enters or exit a region. 在您的情况下,即使用户已停止移动一段时间然后开始移动,应用程序将在应用程序进入或退出区域时被唤醒/委托。

4- Make sure to use locationManager: didDetermineState: forRegion: as well. 4-确保使用locationManager:didDetermineState:forRegion:。 This will allow the app to determine if it is inside or outside of the region at start. 这将允许应用程序在开始时确定它是在区域内部还是外部。 This is useful when you think of an app being launched and no region crossing has happened but it is important to know whether the user is inside or outside of the region. 当您想到正在启动的应用程序并且没有发生区域交叉时,这很有用,但重要的是要知道用户是在区域内还是在区域外。

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM