iphone - Running the code when application is in the background or device is locked -


i have piece of code wherein make server call , based on response play sound. now, not work when application in background or devicei locked.

is there way can execute piece of code (server call , response handling) if app in background or device locked?

there no general solution, design. (apple not want have potentially cpu- , power-intensive process running in background , degrading user experience.)

there few limited-case options available:

  1. you said want play sound. if mean "play music" or such streaming, there audio background task application can register perform. note must actually streaming audio; apple rightfully frowns upon apps try use approach circumvent general-case prohibition , reject app store submission accordingly.
  2. you can invert scenario , have server send push notification through apple push notification service. depending on user's settings, alert, badge, or sound can result. might best fit if aren't streaming audio.
  3. if intending is, say, finish upload or download (and sound completion notification), can request additional time finish task after app nominally backgrounded or device locked. use -[uiapplication beginbackgroundtaskwithexpirationhandler:] within appropriate uiapplicationdelegate methods register such task. note have limited (but appreciable) amount of time finish task, , don't think can play media in mode.

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -