Detecting Low Power Mode In iOS
Posted By : Vasu Saini | 29-Jan-2018
Today I will demonstrate to you proper methodologies to identify when the client has influenced the gadget to go into low power mode and to stay refreshed on the mode as it changes. I will demonstrate to you generally accepted methods to achieve this utilizing a property from the class NSProcessInfo called: LowPowerModeEnabled and after that tuning into the state change utilizing: NSProcessInfoPowerStateDidChangeNotification.
As of present, the Xcode iOS Simulators don't have the choice to empower/handicap Low Power Mode. To test this undertaking, you should put this on your gadget.
What actually Low power mode is?
Low power mode is another way that Apple is handling their regularly diminishing batteries. It stops all foundation action, diminishes the screen and uses diverse advantages for spare power. It's truly slick to be reasonable, I have made due on 1% for 30 minutes prior. I know, Sounds like a lie, yet believe me. It is not.
What is a need for detecting low power mode?
Situation:
Give us a chance to expect that your application interfaces with a web-server each 15mins out of sight. Like the iOS mail application (Depending on your settings). It at that point refreshes information, its urgent information that the client (We will call her… Linda) is hoping to show up, Linda utilizes the warnings to make due in a quick paced world, her reality and her business rely upon getting these notices. In any case, at that point, Low power mode goes ahead and stops foundation exercises. It's alright until further notice, she realizes that in 1 hour she will have a power supply and the low power mode will kill. Along these lines, after one hour, she connects to her gadget, murmurs alleviation and approaches her day. Later that night she meets a companion (Sarah) who has all the most recent babble, business news and is leaving for the end of the week since she found an astounding arrangement. Linda is befuddled on the grounds that she didn't get any of this data, she has passed up a major opportunity for a key deal, an about consummation Ebay thing and an end of the week away Groupon voucher for $29. Linda is embarrassed, she understands that after low power mode her application didn't return on, didn't begin its typical foundation movement and generally made her experience a low, icy and frightful one.
Try not to hurt individuals like Linda.
Presently you are recognizing the low power mode status, you can modify your applications movement in like manner.
Linda likes this.
For this example, we will make a fundamental application that will endeavor to download a video from youtube. Not really remove and download onto the gadget just load.We will identify low power mode utilizing quick and concede the activity until after the low power mode is deactivated.
Step 1. Create a new project or open project in which you have to detuct low power mode.
Step 2. Declare varibles in ViewController.swift as shown below:-
var StartVideoDownload = true
let processInfo = NSProcessInfo.processInfo()
A NSProcessInfo question is made the first run through this technique is summoned, and that same protest is returned on each resulting conjuring.
Step 3. Now we will create a function
func downloadStart(){
guard let url = NSURL(string: "https://www.youtube.com/embed/YQHsXMglC9A") where
!processInfo.lowPowerModeEnabled else{
return
}
StartVideoDownload = false
}
Step 4. Now we will add powerModeChanged() method.
func powerModeChanged(notif: NSNotification){
guard mustDownloadVideo else{
return
}
downloadStart()
}
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Vasu Saini
Vasu Saini is Passionate to deploy ideas into real world, Have zeal to learn new technologies. working as iOS Developer in Oodles Technologies. Sports Freak, Calisthenics ,Parkour, Love to play football, swimmer, athletics etc