Introduction:
When most apps have no touches as user input for a short period, the system puts the device into a "sleep” state where the screen dims. This is done for the purposes of conserving power. But in some time we may need to disable device sleep mode, this article can explain you about to disable/enable device sleep mode in iOS.
Requirements:
When most apps have no touches as user input for a short period, the system puts the device into a "sleep” state where the screen dims. This is done for the purposes of conserving power. But in some time we may need to disable device sleep mode, this article can explain you about to disable/enable device sleep mode in iOS.
Requirements:
- This article source code is prepared by using Visual Studio Community for Mac (7.3.2). And it is better to install latest visual studio updates from here.
- This article is targeted for Xamarin.iOS and tested in iPhone 7 physical device.
Description:
Sometime, apps may need to prevent the sleeping mode to enhance user experience. For example, an app that play video would not go into sleep while the movie is playing. In IOS, a simple task can be done to prevent the app run into a sleep mode.
Note: Just remember to turn on the sleeping mode whenever the task finish. (for example, when your app stop playing video, you should turn the sleeping mode on again.
Note: Just remember to turn on the sleeping mode whenever the task finish. (for example, when your app stop playing video, you should turn the sleeping mode on again.
1. How to Prevent iOS app from device sleeping mode?
We can use the IdleTimerDisabled property that can controls whether the idle timer is disabled for the app. And default value of this property is false, so simply call below method in your AppDelegate source or ViewController to disable device sleep mode.
Reference:
- public void DisableDeviceSleepMode()
- {
- InvokeOnMainThread(() => {
- UIApplication.SharedApplication.IdleTimerDisabled = true;
- });
- }
- public void EnableDeviceSleepMode()
- {
- InvokeOnMainThread(() => {
- UIApplication.SharedApplication.IdleTimerDisabled = false;
- });
- }
Reference:
FeedBack Note: Please share your thoughts, what you think about this post, Is this post really helpful for you?. It would be very happy, if you have any thoughts for to implement this requirement in any other way? I always welcome if you drop comments on this post and it would be impressive.
No comments:
Post a Comment