You have 2 options.
1. Turn off the idle timer: This code will not allow your iPhone to sleep while your application is running. I'm not sure if this will prevent the device from locking, but you can prevent the screen from using the UIpplication idleTimerDisabled function.
[UIApplication sharedApplication].idleTimerDisabled = YES;
From the documentation:
Important: you should set this property only if necessary, and you must be sure that reset is NOT when the need no longer exists. Most applications should let the system turn off the screen when the idle timer expires. This includes sound applications. With proper use of the audio session services, playback and recording continue uninterrupted when the screen turns off. The only applications that should turn off the idle timer are matching applications, games, or similar programs with sporadic user interactions.
2. Make a background-enabled app: You can follow this guide to Backgrounds in iOS .
Here's a quick overview of the five main background modes available in iOS:
- Play audio: the application can continue to play and / or record sound in the background.
- Receive location updates: The app can continue to receive callbacks when changing device locations.
- Perform tasks of finite length: a common βanyβ case where an application can run arbitrary code for a limited period of time.
- Downloadable Newsstand Kit downloads: specific to Newsstand applications, the application can download content in the background.
- Providing Voice-over-IP (VoIP) services: the application can run any arbitrary code in the background. Of course, Apple restricts its use, so your application must also provide VoIP services.
Background VOIP allows your application to run arbitrary code in the background. This mode is better than the Independent API because you can run the code indefinitely. Even better, if the application crashes or the user restarts the phone, the application starts automatically in the background. If you're interested, you can follow Apple's VoIP application development tips . Your application must provide the user with some kind of VoIP feature, or Apple will reject your application.
source share