我正在使用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 分钟)处于后台模式,但不是无限的。