切换 iPhone 上的接近传感器会丢失事件

发布于 2024-07-15 10:17:37 字数 1359 浏览 4 评论 0原文

我正在使用 setProximitySensingEnabled 并在我的 UIApplication 子类中实现 proximityStateChanged。 看起来如果切换传感,第一个“关闭”事件就会丢失。

我的 UIApplication 类非常基本...

  -(void)proximityStateChanged:(BOOL)state { NSLog(state ? @"ON" : @"OFF"); }

在我的应用程序委托中,我有一个 UISwitch 可以启用/禁用接近传感器。

-(IBAction)toggleProxy:(id)sender { [UIApplication sharedApplication].proximitySensingEnabled = prox.on; }

“prox”是我的 UISwitch。 测试第一次启动时运行良好。 我点击开关将其打开,然后将手放在传感器上一秒钟,然后将其移开并得到:

2009-03-11 12:43:00.465 Proximity[324:20b] ON
2009-03-11 12:43:02.514 Proximity[324:20b] OFF
2009-03-11 12:43:04.046 Proximity[324:20b] ON
2009-03-11 12:43:05.621 Proximity[324:20b] OFF

然后我点击开关将其关闭,然后再次点击将其打开。 现在我得到:

2009-03-11 12:43:12.005 Proximity[324:20b] ON
2009-03-11 12:43:14.789 Proximity[324:20b] ON
2009-03-11 12:43:16.467 Proximity[324:20b] OFF
2009-03-11 12:43:17.516 Proximity[324:20b] ON
2009-03-11 12:43:19.077 Proximity[324:20b] OFF

请注意,在关闭之前我得到了两次开启。 OFF 在某处丢失了。 我无法使用谷歌的移动应用程序复制这种行为,所以我想知道他们是否正在重置邻近启用之间的某些内容。 他们没有一直打开接近传感器,因为如果你盖住传感器,屏幕不会变成空白。 您必须将手机向上倾斜并向后倾斜(以模拟它在您耳边的位置),然后覆盖传感器即可。

还有人玩传感器吗?

在我的特定应用程序中,我正在录制语音消息,当您将手机从耳朵上移开时,我想暂停录制(当我关闭时)。 当我第一次将手机从耳边移开时,录音不会暂停。 但是,如果我将它放在耳边并再次将其移开,它就会暂停。

I'm using setProximitySensingEnabled and implemented proximityStateChanged in my UIApplication subclass. It looks like if sensing is toggled, that the first "off" event is being lost.

My UIApplication class is pretty basic...

  -(void)proximityStateChanged:(BOOL)state { NSLog(state ? @"ON" : @"OFF"); }

In my application delegate, I have a UISwitch that enables/disables the proximity sensor.

-(IBAction)toggleProxy:(id)sender { [UIApplication sharedApplication].proximitySensingEnabled = prox.on; }

"prox" is my UISwitch. The test works fine when it first starts. I tap the switch to turn it on and then put my hand over the sensor for a second then move it away and get:

2009-03-11 12:43:00.465 Proximity[324:20b] ON
2009-03-11 12:43:02.514 Proximity[324:20b] OFF
2009-03-11 12:43:04.046 Proximity[324:20b] ON
2009-03-11 12:43:05.621 Proximity[324:20b] OFF

I then tap the switch to turn it off then tap again to turn it on. Now I get:

2009-03-11 12:43:12.005 Proximity[324:20b] ON
2009-03-11 12:43:14.789 Proximity[324:20b] ON
2009-03-11 12:43:16.467 Proximity[324:20b] OFF
2009-03-11 12:43:17.516 Proximity[324:20b] ON
2009-03-11 12:43:19.077 Proximity[324:20b] OFF

Notice I get two ON's before an OFF. The OFF is lost somewhere. I can't replicate this behavior using Google's mobile app so I'm wondering if they're resetting something in between proximity enabling. They don't have the proximity sensor on all the time because if you cover the sensor, the screen doesn't go blank. You have to tilt the phone up and angle it back (to simulate the position it would be in at your ear) and then covering the sensor works.

Anyone else playing with the sensor?

In my particular app, I'm recording a voice message and when you move the phone away from your ear, I want to pause the recording (when I get an OFF). The first time I move the phone away from my ear, the recording is not paused. However, if I put it to my ear and move it away again, it is paused.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文