GPS位置/区域监控回顾+如何在后台打开/关闭GPS信号(图标)[iOS] [英] GPS location/Region monitoring recap + how to switch on/off the gps signal (icon) in background [iOS]

查看:250
本文介绍了GPS位置/区域监控回顾+如何在后台打开/关闭GPS信号(图标)[iOS]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果在应用程序处于后台模式时可以完全关闭gps,并且终止它(long即使区域监控处于活动状态并且App .plst中存在相应的活动标志,也可按下主页按钮,点击相应任务的X。)



另外我想回顾一下如何监控设备位置;我认为有三种方法:
- [locationManager startUpdatingLocation]
- [locationManager startMonitoringSignificantLocationChanges];
- [locationManager startMonitoringForRegion:region desiredAccuracy:accuracy];

我不明白他们可以/不可以/ 在同一时间运行。例如:startUpdatingLocation和startMonitoringSignificantLocationChanges是互斥的,没关系,但startMonitoringForRegion怎么样?

我可以只使用startMonitoringForRegion而不使用startMonitoringSignificantLocationChanges吗?



如果我同时使用两者,我可以在进入/退出监控区域时收到两个通知吗?我怎样才能避免它?
我这种情况下,我应该实现这样的事情:

   - (void)locationManager:(CLLocationManager *)经理didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
BOOL crossedBoundary = [self checkIfNewLocationHasCrossedMyMonitoredRegionBoundary:newLocation];
if(crossedBoundary)NSLog(@跨越边界);

AND



<$ p (CLLocationManager *)管理器didEnterRegion:(CLRegion *)region {NSLog(@Crossed the boundary); $ p> - (void)locationManager: }

E)当应用程序在后台时,如何关闭startMonitoringForRegion?



非常感谢。
我从Regions和breadCrumb开始Apple示例
https://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html#//apple_ref / doc / uid / DTS40010048-Intro-DontLinkElementID_2



https://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.html

解决方案

回答您的问题

答案A)您不能将位置服务关闭为就像我尝试过的那样。

答案B) startMonitoringForRegion 在应用程序外运行监控区域进入/退出状态的服务。它的位置不会从正在从位置服务更新当前位置的 CLLocationManager 更新。答案C)是的,你可以单独使用它们,因为 startMonitoringForRegion 添加要监视的区域作为 startMonitoringSignificantLocationChanges 的位置服务是监视技术,通过该技术,可以使用 locationManager:didUpdateLocations:处理更大的位置更改并更新到 CLLocationManager 。但正如前面的回答中所提到的,启动监控区域会将监控区域添加到区域监控位置服务中。

Ans D)是的,您会收到单独的更新到位置。但请记住 startMonitoringSignificantLocationChanges 将位置更新为 CLLocationManger 。在那里,startMonitoringForRegion仅在边界交叉点更新,并且不更新位置。



答案E)您必须将 stopMonitoringRegion 添加到应用程序的AppDelegate中的appEnterBackground


I'l like to know

A) if it's possible to completely switch off the use of gps when the App is in background mode and I terminate it (long press on "home button", tap on the "X" of the corresponding task), even if "region monitoring" is active and there is the corresponding active flag in the App .plst .

Also I'd like to recap how you can monitor the device location; I think there are three ways: - [locationManager startUpdatingLocation] - [locationManager startMonitoringSignificantLocationChanges]; - [locationManager startMonitoringForRegion:region desiredAccuracy:accuracy];

B) i don't understand if they "can"/"may not"/"have to" run at the same time. for example: startUpdatingLocation and startMonitoringSignificantLocationChanges are mutually exclusive and that's ok, but what about startMonitoringForRegion?

C) Can i use only startMonitoringForRegion without startMonitoringSignificantLocationChanges?

D) if i use both at the same time, may i receive two notifications while entering/exiting a monitored region? How can I avoid it? I this case, think i should implement something like this:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation   {
 BOOL crossedBoundary = [self checkIfNewLocationHasCrossedMyMonitoredRegionBoundary:newLocation ];
if (crossedBoundary) NSLog(@"Crossed the boundary");
}

AND

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region  {  NSLog(@"Crossed the boundary"); }

E) How can i turn off/on startMonitoringForRegion while the App is in background?

Thanks very much. I'm starting from "Regions" and "breadCrumb" Apple example https://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010048-Intro-DontLinkElementID_2

https://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.html

解决方案

Answering your questions in order

Ans A) You can't switch off location services as far as I have tried.

Ans B) startMonitoringForRegion is running a service outside of the app monitoring the region entry/exit status. It's location is not updated from the CLLocationManager that is updating the current location from the location services. It just stores the monitored regions with respect to the application.

Ans C) Yes you can use them separately because startMonitoringForRegion adds regions to monitor on the location services where as startMonitoringSignificantLocationChanges is the monitoring technique by which the larger changes in location are handled and updated to the CLLocationManager using locationManager:didUpdateLocations:. But as mentioned in the previous answer startMonitoringForRegion will add region for monitoring to the region monitoring location service

Ans D) Yes you will receive separate updates to location. But keep in mind startMonitoringSignificantLocationChanges updates the location to the CLLocationManger. Where as the startMonitoringForRegion updates only on boundary crossings and doesn't update location.

Ans E) You have to add stopMonitoringRegion to the appEnterBackground in the application's AppDelegate

这篇关于GPS位置/区域监控回顾+如何在后台打开/关闭GPS信号(图标)[iOS]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆