Application idle Timer disable not working - ios

Application idle timer disable is not working properly after record video from the application. I put below code in my application did finish launching. please suggest me if any one have idea to handle idle timer.
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

In the past there have been some bugs in iOS, in which it forgets that you have set idleTimerDisabled, for example after you have used the UIImagePickerController to take a picture. I am not sure whether Apple has fixed those bugs completely yet.
A work-around is to set it more often, for example in the viewWillAppear of your main view.

Related

Application functionality changes when run on device

I've found that my application stops its timer when the device goes to the lock screen on actual device, but it works perfectly on the simulator.
Is that because I haven't released the app, so an actual device won't let me keep working on the lock screen? Or is it a bug in my code?
I've written an NSLog() statement to monitor my application's timer action, it keeps working when the simulator goes to the lock screen,
but on an actual device it stops.
I'm so frustrated because I don't know why there are these differences between the device and the simulator, and I don't know how to solve it.
What you need to do is implement applicationWillEnterForeground and applicationDidEnterBackground to persist the state of your timer, and resume it whenever the app opens again.
You may also want to use UILocalNotification to schedule a notification when your timer finishes.
Here is another post about using UILocalNotification with timers that you may find useful.

NSTimer when screen is locked

How do I keep the NSTimer persisting after the screen is locked in iOS 8? Every time I lock the screen it stops. I have tried putting it in an NSRunLoop to no luck.
iOS always suspends NSTimers when the app is backgrounded. You can request some extra background time by using UIApplication beginBackgroundTaskWithExpirationHandler: but be warned that it won't keep your timer going forever. Your best bet is to remember what time you are backgrounded in applicationWillResignActive and then check the current time when you are re-activated in applicationDidBecomeActive or applicationWillEnterForeground. Then you can calculate how much time passed when your app was inactive and do whatever is appropriate.
See the UIApplication docs here https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html, particularly the section on "Managing Background Execution".

iOS App prevents device from sleep mode

I've a really strange behavior of my iOS app. It prevents the device from going to standby. I've already searched if there is anywhere the idleTimeDisabled flag set, but this isn't the case. The idle timer inside the settings app is set to 2 minutes and works within other apps. The device isn't jailbroken and the even restarting the device didn't help. The app was written by somebody else and I'm new to it. So in the moment I don't have any idea what to look for. Has anybody of you an idea, why this could be the case or how I could figure out what's the reason for this behavior?
Thank you very much!
If your app is using AVPlayer or some other similar AVFoundation functionality, this can be the cause.
If AVPlayer is playing a video, a device will not go to sleep while a video is playing.
If the video is playing in a loop, the device will never go to sleep.
Edit:
With iOS 12 this is now possible by setting
player.preventsDisplaySleepDuringVideoPlayback = false
Put this line in your ViewController that require not being in sleep mode
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most
applications should let the system turn off the screen when the idle
timer elapses. This includes audio applications. With appropriate use
of Audio Session Services, playback and recording proceed
uninterrupted when the screen turns off. The only applications that
should disable the idle timer are mapping applications, games, or
similar programs with sporadic user interaction.
Make sure you are not "testing" with your Xcode. Because it will always remained as turn on status as long as you plugin your iPhone with a cable.

How to create a custom alarm wake up screen on iOS?

Is it possible to create a custom alarm wake up screen on iOS via Xcode, such as the carrot alarm app on the App Store? If so, could anyone point to some documentation or examples?
I'm pretty confused at the moment, because I don't understand how it can be done as long as the iPhone locks itself and the app stops working. This is my main concern, because locking the iPhone kills the app.
I would like to what's the best way to create a wake up screen like carrot app's one, avoiding all the screen lock problems. How did they do it?
Thanks
Using the code below you can disable the lock screen. You can place it in your viewDidLoad method.
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
As for creating the screen, I'd suggest picking up a book on iPhone development as it's a lot to explain in a follow-up message.

How to re-enable the idle timer in ios once it has been disabled (to allow the display to sleep again)?

I have figured out how to stop an iOS device from going to sleep (see below), but I am having troubles undoing that setting. According to the Apple Documentation, it should just be changing the value of the idleTimerDisabled property. But when I test this, it does not work.
This is how I am initially stopping the device from going to sleep:
//need to switch off and on for it to work initially
[UIApplication sharedApplication].idleTimerDisabled = NO;
[UIApplication sharedApplication].idleTimerDisabled = YES;
I would have thought that the following would do the trick:
[UIApplication sharedApplication].idleTimerDisabled = NO;
From the Apple Documentation:
The default value of this property is NO. When most applications 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. However, applications that don't have user input except for the accelerometer—games, for instance—can, by setting this property to YES, disable the “idle timer” to avert system sleep.
Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most applications should let the system turn off the screen when the idle timer elapses. This includes audio applications. With appropriate use of Audio Session Services, playback and recording proceed uninterrupted when the screen turns off. The only applications that should disable the idle timer are mapping applications, games, or similar programs with sporadic user interaction.
Are you trying this when you Run from Xcode? Running from Xcode always disables the idle timer, regardless if you set [UIApplication sharedApplication].idleTimerDisabled or not. You can try it by manually opening the app from the iPhone/iPod touch/iPad.

Resources