ios - 如何为超过 20 个区域启动 MonitoringForRegion

标签 ios xcode core-location locationmanager region

我正在使用它,但我不知道如何监控超过 20 个区域,因为它在 ios 中可以监控的最大区域数

if ([AllRegionsArray count] > 0) {


    for (int i = 0; i < [AllRegionsArray count]; i++) {
        NSArray *LongLati = [AllRegionsArray objectAtIndex:i];
        lutiuid = [LongLati objectAtIndex:0];
        Longtuid = [LongLati objectAtIndex:1];

        CLLocationCoordinate2D centreLoc = {[lutiuid floatValue], [Longtuid floatValue]};
        CLLocationDistance regionRadius = 150.00;
        CLRegion *grRegion = [[CLRegion alloc] initCircularRegionWithCenter:centreLoc radius:regionRadius identifier:[NSString stringWithFormat:@"grRegion%i",i]];

        [locationManager startMonitoringForRegion:grRegion desiredAccuracy:acc];

        NSLog(@"Mon = %i , %i",[locationManager.monitoredRegions count],i);

    }


}

最佳答案

您无法监控超过 20 个区域。也许您可以根据用户位置停止监视某些区域并开始监视其他区域(取决于您的用例)。

Discussion You must call this method once for each region you want to monitor. If an existing region with the same identifier is already being monitored by the application, the old region is replaced by the new one. The regions you add using this method are shared by all location manager objects in your application and stored in the monitoredRegions property.

Region events are delivered to the locationManager:didEnterRegion: and locationManager:didExitRegion: methods of your delegate. If there is an error, the location manager calls the locationManager:monitoringDidFailForRegion:withError: method of your delegate instead.

An app can register up to 20 regions at a time. In order to report region changes in a timely manner, the region monitoring service requires network connectivity.

In iOS 6, regions with a radius between 1 and 400 meters work better on iPhone 4S or later devices. (In iOS 5, regions with a radius between 1 and 150 meters work better on iPhone 4S and later devices.) On these devices, an app can expect to receive the appropriate region entered or region exited notification within 3 to 5 minutes on average, if not sooner.

https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instm/CLLocationManager/startMonitoringForRegion :

关于ios - 如何为超过 20 个区域启动 MonitoringForRegion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17088728/

相关文章:

ios - swift ios 如何从 Collection View 访问数据

ios - 当我在 tabBarController 中的选项卡之间切换时会调用哪个方法?

ios - 应用程序中的状态栏消失了(Xcode iphone)

ios - 使用命令行工具发送命令以在 iOS 设备中启动应用程序

ios - 如何从 swift 中的 didUpdateToLocation 方法获取旧位置值

iphone - iOS 上的蓝牙

ios - RxAlamofire: retryWhen 掉进订阅 block

ios - Swift 3 Game Center Leaderboard 不保存分数的值

iphone - iOS CoreLocation 仅在美国无法通过 3G 运行

ios - 定位服务在 iPhone 5 中进入 "Inactive"状态