2

我正在使用CLLocationManager对象按照以下代码启动信标测距。还可以从 Target -> Capabilities 启用背景模式。

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=kCLDistanceFilterNone;
locationManager.pausesLocationUpdatesAutomatically = NO;
[locationManager requestAlwaysAuthorization];

还将 AllowsBackgroundLocatoinUpdates 添加为 YES

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
   locationManager.allowsBackgroundLocationUpdates = YES;
}

一个布尔值,指示应用程序是否希望在挂起时接收位置更新。

CLBeaconRegion对象上创建以范围信标,如

CLBeaconRegion *beacon_Region;
beacon_Region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:mjorVa minor:minorVa identifier:tmpStrIdentifier];
beacon_Region.notifyEntryStateOnDisplay = YES;
beacon_Region.notifyOnEntry=YES;
beacon_Region.notifyOnExit=YES;
[locationManager startRangingBeaconsInRegion:beacon_Region];

它在某个时间段(例如 10 分钟或某个时间 20 分钟)处于后台模式,但不是无限的。

4

1 回答 1

0

如何最大化信标响应能力:

1 .为了在前台最快的监测检测时间,只要你监测,就做测距,即使你不关心测距更新。像这样:

CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"] major: 1 minor: 1 identifier: @"region1"];
region.notifyEntryStateOnDisplay = YES;
[_locationManager startMonitoringForRegion:region];
[_locationManager startRangingBeaconsInRegion:region];

2 .如果您想在用户唤醒手机时在后台获得有保证的额外监控更新,请在您的区域设置 notifyEntryStateOnDisplay 选项,如下所示:

CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"] major: 1 minor: 1 identifier: @"region1"];
region.notifyEntryStateOnDisplay = YES;
[_locationManager startMonitoringForRegion:region];

如果您想了解更多,请关注本文

于 2016-09-15T11:22:21.617 回答