GPS 位置/区域监控回顾 +如何在后台打开/关闭GPS信号(图标)[iOS]
我想知道
A) 当应用程序处于后台模式并终止它时是否可以完全关闭 GPS 的使用(长按“主页按钮”,点击相应任务的“X”) ,即使“区域监控”处于活动状态并且 App .plst 中有相应的活动标志。
我还想回顾一下如何监控设备位置;我认为有以下三种方式: - [locationManager 开始更新位置] - [locationManager startMonitoringSignificantLocationChanges]; - [locationManager startMonitoringForRegion:regiondesiredAccuracy:accuracy];
B)我不明白它们是否“可以”/“可能不”/“必须”同时运行。例如:startUpdatingLocation 和 startMonitoringSignificantLocationChanges 是互斥的,这没关系,但是 startMonitoringForRegion 呢?
C) 我可以仅使用 startMonitoringForRegion 而不使用 startMonitoringSignificantLocationChanges 吗?
D) 如果我同时使用两者,我在进入/退出受监控区域时是否可以收到两个通知?我怎样才能避免它? 在这种情况下,我认为我应该实现这样的东西:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
BOOL crossedBoundary = [self checkIfNewLocationHasCrossedMyMonitoredRegionBoundary:newLocation ];
if (crossedBoundary) NSLog(@"Crossed the boundary");
}
并且
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { NSLog(@"Crossed the boundary"); }
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按顺序回答您的问题
Ans A) 据我尝试,您无法关闭定位服务。
Ans B) startMonitoringForRegion 正在应用程序外部运行一项服务,监视区域进入/退出状态。它的位置不是从从位置服务更新当前位置的 CLLocationManager 中更新的。它仅存储与应用程序相关的受监控区域。
答 C) 是的,您可以单独使用它们,因为 startMonitoringForRegion 添加了要在位置服务上监视的区域,其中 startMonitoringSignificantLocationChanges 是处理较大位置变化的监视技术,并且使用 locationManager:didUpdateLocations: 更新到 CLLocationManager。但正如前面的答案中提到的 startMonitoringForRegion 会将用于监控的区域添加到区域监控位置服务
Ans D) 是的,您将收到单独的位置更新。但请记住,startMonitoringSignificantLocationChanges 将位置更新为 CLLocationManger。其中 startMonitoringForRegion 仅在边界交叉点更新,而不更新位置。
Ans E) 您必须将 stopMonitoringRegion 添加到应用程序 AppDelegate 中的 appEnterBackground
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
It will stop Calling GPS