gpt4 book ai didi

iphone - iPhone 4S 找不到 iBeacon

转载 作者:行者123 更新时间:2023-12-03 19:08:56 25 4
gpt4 key购买 nike

我遇到了一个涉及 iPhone 4S 的奇怪问题。我正在开发一个使用 iBeacons 的应用程序。以下代码是在 iPad mini、iPhone 5s 和 iPhone 4s 上运行的代码,但只有 iPad 和 5S 在遇到 iBeacon 时能够响应,而 4S 没有任何反应。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

//start ibeacon monitoring mode
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
[self enableMonitoring];
}

- (void)enableMonitoring
{
[self initRegion];
[self locationManager:self.locationManager didStartMonitoringForRegion:self.beaconRegion];
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}

- (void) initRegion
{
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:UUID]
identifier:@"iBeacon"];
[self.locationManager startMonitoringForRegion:self.beaconRegion];
hasAlerted = NO;
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
ST_UNUSED(manager);
ST_UNUSED(region);
NSLog(@"Beacon Found");
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
ST_UNUSED(manager);
ST_UNUSED(region);
NSLog(@"Left Region");
[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
}

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
ST_UNUSED(manager);
ST_UNUSED(region);
CLBeacon *beacon = [beacons lastObject];

// stuff gets done here

}

4S可以毫无问题地广播iBeacons,另外2个可以找到它们。

我已经在 4S 上完成了 [CLLocationManager isMonitoringAvailableForClass:[CLBeacon class]][CLLocationManager isRangingAvailable] 测试,并且没有失败。

谁能告诉我这只是我们4S的问题,还是整个4S的问题?

最佳答案

我认为您的设备没有缺陷,因为我也遇到了完全相同的问题!相同的代码在 5S 上运行良好,但在 4S 上找不到信标。结果(看起来)4S BLE 堆栈的工作方式与 5S 略有不同。

按照我编写代码的方式,直到调用“locationManager didDetermineState forRegion”并且我确定我实际上位于信标区域内时,我才开始对信标进行测距。这在 iPhone 5S 上效果很好,而且您不会无缘无故地进行范围调整。但在 4S 上你永远不会接到回电!

但是,如果您通过以下方式提前开始测距:

[locationManager startRangingBeaconsInRegion:beaconRegion];

在“locationManager didStartMonitoringForRegion”回调中,它工作得非常出色!

关于iphone - iPhone 4S 找不到 iBeacon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20328499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com