【发布时间】:2012-03-07 15:07:32
【问题描述】:
我想知道
A) 如果可以在应用程序处于后台模式时完全关闭 gps 的使用并且我终止它(长按“主页按钮”,点击相应任务的“X”),即使“区域监控”处于活动状态,App .plst 中有相应的活动标志。
我还想回顾一下如何监控设备位置;我认为有三种方式: - [locationManager startUpdatingLocation] - [locationManager startMonitoringSignificantLocationChanges]; - [locationManager startMonitoringForRegion:region desiredAccuracy: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
【问题讨论】:
标签: iphone objective-c gps cllocationmanager region