gpt4 book ai didi

ios - 注册区域 ios 时是否需要 startLocationUpdates?

转载 作者:行者123 更新时间:2023-11-28 20:08:48 25 4
gpt4 key购买 nike

在我的应用程序中,我注册了一些 CLRegion。我的全部功能在于这些功能:

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"Entered Region - %@", region.identifier);
[self showRegionAlert:@"Entering Region" forRegion:region.identifier];
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
NSLog(@"Exited Region - %@", region.identifier);
[self showRegionAlert:@"Exiting Region" forRegion:region.identifier];
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
NSLog(@"Started monitoring %@ region", region.identifier);
}

这个函数存在于我的代码中,但我没有在这里做任何事情:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"Location Update:%@",[NSString stringWithFormat:@"%f,%f",newLocation.coordinate.latitude, newLocation.coordinate.longitude]);
}

我的问题是:

这个初始化是必要的吗?

- (void)initializeLocationUpdates {
[_locationManager startUpdatingLocation];
}

当您只想考虑区域时?

最佳答案

不,但是您必须为每个要监视的区域调用 startMonitoringForRegion:。像这样:

CLRegion *region = // Set up your region
self.locationManager.delegate = self; // Make sure you are set as the location manager's delegate
[self.locationManager startMonitoringForRegion: region]; // Start monitoring the region

请参阅 this page 上的 startMonitoringForRegion: 文档

关于ios - 注册区域 ios 时是否需要 startLocationUpdates?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21065646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com