【发布时间】:2015-06-19 10:13:11
【问题描述】:
iPhone 上的接近传感器有问题。似乎当禁用空闲计时器并启用接近监控时,屏幕(有时)会在收到通知时打开。在此之后,接近状态报告不正确,屏幕不会再次关闭。
我提供了一个示例项目来说明问题。但是重现的步骤非常简单。我在具有多个 iOS 版本(7.0.3 和 8.3)的多部手机(4S、5、6、6+)上对此进行了测试。当手机未连接电源或调试器时,它似乎最可靠。
我唯一的 ViewController 中的代码是(视图是在故事板中创建的):
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var checkingToggleButton: UIButton!
@IBOutlet weak var debugLabel: UILabel!
@IBOutlet weak var screenDebugLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.checkingToggleButton.setTitle("Start checking", forState: UIControlState.Normal)
self.debugLabel.text = "Not checking"
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("proximityChanged:"), name: "UIDeviceProximityStateDidChangeNotification", object: nil)
}
@IBAction func handleCheckingToggle(sender: AnyObject) {
let enabled = !UIDevice.currentDevice().proximityMonitoringEnabled
if enabled {
self.debugLabel.text = "Checking"
self.checkingToggleButton.setTitle("Stop checking", forState: UIControlState.Normal)
} else {
self.debugLabel.text = "Not checking"
self.checkingToggleButton.setTitle("Start checking", forState: UIControlState.Normal)
}
UIApplication.sharedApplication().idleTimerDisabled = enabled
UIDevice.currentDevice().proximityMonitoringEnabled = enabled
}
func proximityChanged(notification:NSNotification)
{
if UIDevice.currentDevice().proximityState{
self.screenDebugLabel.text = "Proximity true"
println("Proximity true")
} else {
self.screenDebugLabel.text = "Proximity false"
println("Proximity false")
}
}
}
重现步骤:
- 在设备上构建提供的示例项目并在断开电源和调试器的设备上运行应用程序(这似乎有所不同)。
- 按“开始检查”按钮启用接近监控并禁用空闲计时器。
- 盖住接近传感器,这会关闭屏幕。
- 等待大约 2 分钟(这也有影响,过早不会重现问题)
- 向自己发送通知(例如 iMessage)
屏幕将打开并且不会再次关闭。我们还创建了一个显示当前接近状态的标签,该状态(错误地)报告为 false。
GitHub 上的示例项目链接: https://github.com/TimPelgrim/ProximityTest
【问题讨论】: