Reputation: 1208
In my application i have some content to be downloaded from a server and when the user starts a download and the app is in-active state the app is going into background state where the downloads are getting stopped and failed.In order to avoid this i tried implementing download continuation in background using "beginBackgroundTaskWithExpirationHandler".This is working only for a certain of period of time and if the device is in background state/sleep mode for longer time,the downloads are getting failed.
In order to avoid the failing of downloads i thought of avoiding the device going into sleep mode while application is downloading content and implemented the same.
I have set the setIdleTimerDisabled to YES as soon as the download is started and reverted the property to NO after completion of download or failure of download.
[[UIApplication sharedApplication] setIdleTimerDisabled:Yes];
The application is restricted in going to sleep mode after a download is started but after completion of dowload,still the application is not going into sleep mode.
After a download is initated the application would never go to sleep mode.
Can some one help me in restricting the device to sleep only during the dowmload is happening.
TNQ
Upvotes: 3
Views: 4263
Reputation: 5418
I had the similar problem on resetting screen brightness. From my research i found that after pressing home button OS take over the control and wont allow you to reset brightness,timer, etc.
You can solve this problem in another way.Provide a local notification on download completed and in applicationWillEnterForeground write your code to enable timer
- (void)applicationWillEnterForeground:(UIApplication *)application {
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
I got this from StackOverflow, but I forgot the link. Sorry.
Upvotes: 1