我正在使用 CLLocationManager 对象来启动信标范围,如下面的代码所示。 还可以从Target启用背景模式 - >能力。
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=kCLDistanceFilterNone;
locationManager.pausesLocationUpdatesAutomatically = NO;
[locationManager requestAlwaysAuthorization];
同时将AllowBackgroundLocatoinUpdates添加到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分钟,但不是无限的。
答案 0 :(得分: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];
如果您想要更多,请遵循ARTICLE