gpt4 book ai didi

ios - didRangeBeacons 委托(delegate)调用 CLProximityNear 和 CLProximityFar 太快了

转载 作者:行者123 更新时间:2023-11-29 12:28:54 25 4
gpt4 key购买 nike

我想插入一个计时器以避免在“远”、“近”、“立即”状态之间切换回来。

我对“远”和“近”状态使用相同的 View ,但我为即时状态推送一个新 View 。

因此对于直接返回 root 的情况,我已经通过这样做找到了解决方案:

[self performSelector:@selector(patchSelectorPopToRoot) withObject:nil afterDelay:4];

如果我使用相同的 View ,我该如何处理“近”和“远”状态?

这是代表:

-(void)beaconManager:(ESTBeaconManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(ESTBeaconRegion *)region
{
// Descriptor on distance to sort the array of beacons by distance
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"distance" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

// Sorting the array of beacons
// Beacon array is sorted based on distance
// Closest beacon is the first one
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];

if([self.beaconsArray count] > 0)
{

if(!self.selectedBeacon)
{
// initialy pick closest beacon
self.selectedBeacon = [beacons objectAtIndex:0];
currentBeaconMinor = self.selectedBeacon.minor;
}
else
{

//Sorting the array of beacons
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];

//Updating the selected beacon with the first element of the array (closest beacon)
if(self.selectedBeacon != [beacons objectAtIndex:0] )
{
self.selectedBeacon = [beacons objectAtIndex:0];
currentBeaconMinor = self.selectedBeacon.minor;
}

}

// Switch on proximity of the closest beacon
switch (self.selectedBeacon.proximity)
{
case CLProximityUnknown:
{
[self DoOnProximityUnknow];

break;
}
case CLProximityImmediate:
{
[self DoOnProximityImmediate];

break;
}
case CLProximityNear:
{
[self DoOnProximityNear];

break;

}
case CLProximityFar:
{
[self DoOnProximityFar];

break;
}

default:
break;

}
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
}
}

这是我想使用定时器(Near)的方法。

-(void)DoOnProximityNear
{
//Starting a timer

//not working :
//[NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];


//not working
/*
double delayInSeconds = 20.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSLog(@"Do some work");
});*/
}

我只想在“Near”方法中设置一个 20 秒的计时器。我想在回到“Far”之前至少停留 20 秒。

我应该在哪里插入这个计时器?我应该等待远距离信号,启动计时器并等待另一个远距离信号,还是应该在到达近距离时启动计时器?

请问我该如何解决这个问题?

预先感谢您的帮助。

最佳答案

在我过去的一项工作中,需要同样的东西。我希望以下内容之一对您有所帮助。在我的例子中,我的逻辑是基于 RSSI(它也经常波动)

方式一为 CLProximityFar 和 CLProximityNear 放置一个计数器,并根据该触发 Action ,计算相同 Proximity 的连续出现次数,如果是,则考虑该 PROximity 并触发其 Action 。

方法 2这完全基于 RSSI 值。为此,您需要使用 10-20 个连续的 RSSI 值,取它们的平均值并在此基础上触发操作。

关于ios - didRangeBeacons 委托(delegate)调用 CLProximityNear 和 CLProximityFar 太快了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28335150/

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