当没有位置管理器的地图视图消失时,如何 "turn off" 位置服务?
How to "turn off" location services when a map view with no location manager disappears?
我在我调用的视图控制器中有一个 MKMapView
:
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
当我导航到另一个视图控制器并且带有地图视图的视图控制器消失时,我仍然有位置服务 运行(我在状态栏中看到箭头)。一旦我不再看到地图,我想将其关闭,但我不知道如何在没有 CLLocationManager
...
的情况下执行此操作
谢谢
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([CLLocationManager significantLocationChangeMonitoringAvailable])
{
if (OUTPUT_LOGS) NSLog(@"Stopped monitoring for significant changes");
[[self locationManager] stopMonitoringSignificantLocationChanges];
}
[[self locationManager] startUpdatingLocation];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([CLLocationManager significantLocationChangeMonitoringAvailable])
{
[self.locationManager startMonitoringSignificantLocationChanges];
}
[[self locationManager] stopUpdatingLocation];
}
这似乎有效:
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
self.mapView.showsUserLocation = NO;
[self.mapView setUserTrackingMode:MKUserTrackingModeNone animated:YES];
}
我在我调用的视图控制器中有一个 MKMapView
:
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
当我导航到另一个视图控制器并且带有地图视图的视图控制器消失时,我仍然有位置服务 运行(我在状态栏中看到箭头)。一旦我不再看到地图,我想将其关闭,但我不知道如何在没有 CLLocationManager
...
谢谢
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([CLLocationManager significantLocationChangeMonitoringAvailable])
{
if (OUTPUT_LOGS) NSLog(@"Stopped monitoring for significant changes");
[[self locationManager] stopMonitoringSignificantLocationChanges];
}
[[self locationManager] startUpdatingLocation];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([CLLocationManager significantLocationChangeMonitoringAvailable])
{
[self.locationManager startMonitoringSignificantLocationChanges];
}
[[self locationManager] stopUpdatingLocation];
}
这似乎有效:
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
self.mapView.showsUserLocation = NO;
[self.mapView setUserTrackingMode:MKUserTrackingModeNone animated:YES];
}