gpt4 book ai didi

iphone - 当手绕传感器移动时,接近传感器打开

转载 作者:行者123 更新时间:2023-12-01 19:08:30 26 4
gpt4 key购买 nike

我正在开发一个应用程序,我想在用户将手移到接近传感器上时获得接近传感器,并获得接近状态值(如0)。当用户第二次移动手的时间值变为1时,我该怎么做?我知道如何启用接近度但是我想在用户绕过代理移动时启用接近。所以我该怎么做呢?使接近。

UIDevice * device=[UIDevice currentDevice];
device.proximityMonitoringEnabled=YES;

if (device.proximityMonitoringEnabled)
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleProximityChange:)
name:UIDeviceProximityStateDidChangeNotification
object:nil];
}
else
{
NSLog(@"Device not capable to support Proximity sensor");
// device not capable
}

并以这种方法捕捉接近状态...
-(void)handleProximityChange:(NSNotification *)notification
{

NSLog(@"Proximity event catch");

}

我将按照每个用户的身份来执行此代码,因此我可以执行此操作,请帮助我执行此操作。

最佳答案

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
count = 0;
condition = 0;
[self addProximitySensorControl];
}

-(void)addProximitySensorControl {

UIDevice *device = [UIDevice currentDevice];
device.proximityMonitoringEnabled = YES;

BOOL state = device.proximityState;
if(state)
{
NSLog(@"YES");
_sensorSupport.text = @"YES";
}
else
{
NSLog(@"NO");
_sensorSupport.text = @"No";
}

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(proximityChanged:)
name:@"UIDeviceProximityStateDidChangeNotification"
object:nil];
}
-(void)proximityChanged:(NSString*)str
{
NSLog(@"i am in proximityChanged");
condition++;
if (condition % 2 == 0) {
count++;
}
_counter.text = [NSString stringWithFormat:@"%d",count];
}

关于iphone - 当手绕传感器移动时,接近传感器打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18395911/

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