I\'m a relatively new user to swift and now, I need to take advantage of the proximity sensor of an iPhone. I don\'t matter the distance, but I want to know when something is ne
Here's my take on this.
func activateProximitySensor() {
let device = UIDevice.currentDevice()
device.proximityMonitoringEnabled = true
if device.proximityMonitoringEnabled {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "proximityChanged:", name: "UIDeviceProximityStateDidChangeNotification", object: device)
}
}
func proximityChanged(notification: NSNotification) {
if let device = notification.object as? UIDevice {
println("\(device) detected!")
}
}