Skip to content

Instantly share code, notes, and snippets.

@elpsk
Created September 28, 2018 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elpsk/8f856e9a7f975147583a84340158511b to your computer and use it in GitHub Desktop.
Save elpsk/8f856e9a7f975147583a84340158511b to your computer and use it in GitHub Desktop.
Swift - detect low power
//
// 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