Reputation: 38162
I have a piece of code wherein I make a server call and based on the response I play a sound. Now, this does not work when my application is in background or my devicei is locked.
Is there any way we can execute this piece of code (Server call and response handling) even if app is in background or device is locked?
Upvotes: 1
Views: 334
Reputation: 8808
There is no general solution, which is by design. (Apple does not want you to have a potentially CPU- and power-intensive process running in the background and degrading user experience.)
There are a few limited-case options available:
-[UIApplication beginBackgroundTaskWithExpirationHandler:]
from within the appropriate UIApplicationDelegate
methods to register such a task. Note that you have a limited (but appreciable) amount of time to finish your task, and I don't think you can play media in this mode.Upvotes: 5