Created
September 28, 2018 10:25
-
-
Save elpsk/8f856e9a7f975147583a84340158511b to your computer and use it in GitHub Desktop.
Swift - detect low power
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LowPowerVC.swift | |
// Created by Pasca Alberto, IT on 10/08/18. | |
// Copyright © 2018 albertopasca.it. All rights reserved. | |
// | |
import UIKit | |
class LowPowerVC: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
lowPowerState() | |
} | |
func lowPowerState() { | |
NotificationCenter.default.addObserver(self, selector: #selector(powerStateChanged), name: Notification.Name.NSProcessInfoPowerStateDidChange, object: nil) | |
} | |
@objc func powerStateChanged(_ notification: Notification) { | |
let lowerPowerEnabled = ProcessInfo.processInfo.isLowPowerModeEnabled | |
print( "LOW POWER STATE: \(lowerPowerEnabled)" ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment