Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- activateProximitySensor()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- func proximityChanged(notification: NSNotification) {
- if let device = notification.object as? UIDevice {
- print("\(device) detected!")
- }
- }
- func activateProximitySensor() {
- let device = UIDevice.current
- device.isProximityMonitoringEnabled = true
- if device.isProximityMonitoringEnabled {
- NotificationCenter.default.addObserver(self, selector: #selector(ViewController.proximityChanged), name: NSNotification.Name(rawValue: "ProximitySensorDidChangeNotification"), object: device)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement