我一直在开发一个应用,该应用使用核心位置注册一个区域以进行监视。
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:proximtyId] identifier:@"com.hospitalintegration.region" ];
if(self.beaconRegion){
[self.locationManager startMonitoringForRegion:self.beaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
[self.locationManager startUpdatingLocation];
然后调用didStartMonitoringForRegion,并且我通过这种方法请求区域状态:
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
if(self.beaconRegion){
[self.locationManager requestStateForRegion:self.beaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
}
在iOS 12中,这似乎工作得很好,didDetermineState被调用了,我得到了我想要的结果。但是在iOS 13上,didDetermineState没有被调用,并且总是以error.domain == kCLErrorDomain和error.code == 5来调用monitoringDidFailForRegion。
苹果的文档说:
如果应用超出了可同时监视的最大区域数,则监视可能会失败。如果该区域的半径距离太大,监视也会失败。
我检查过的那不是问题。该区域很小,因为它可以在iOS 12上运行,而且我只监视1个区域,而我检查了监视区域的数量,所以它是1。所以,我在这里不知道出什么问题了。