Category: Iphone2013-01-24 14:03 986 people read reviews (0) favorite reports We know that iOS can get up to 600 seconds of execution time after the background task is turned on, and how do some apps that need to download in the background or stay connected to the server break the 600-second limit? Like NetEase Open class can continue to download in the background, Youku can also continue to cache in the background, how is this done? Generally speaking, you need to declare VoIP, audio, or GPs in order to run iOS for a long time. Audiosession implementation method is simple, is to play a silent music file in the background, so that the equivalent of declaring audio, you can easily break through the 600-second limit. by playing a "silent" sound so that the program executes in the background (that is, using the kaudiounitrenderaction_outputissilence flag bit in the AudioUnit callback function), although it is true that background execution can be implemented, there are many limitations in practice. The biggest problem is that the audiosession of the program cannot be interrupted. When the program executes in the background, as long as another program uses kaudiosessioncategory_recordandplay (such as Skype) or Kaudiosessioncategory_ Soloambientsound (the impression of using this session is not many), then this program will be immediately interrupted. The interrupt itself is not a problem, but when the player is interrupted, the only thing that can be obtained is to handle audiosessioninterruption for a short period of time. My lab test was about 3-5 seconds, but because the program then paused immediately, unable to hang the debugger, it was difficult to estimate accurately, and the program was immediately put into hibernation. This time is roughly the same time as the Applicationdidenterbackground callback function, but because the interrupt is accompanied by a broadcast callback action, the program structure is not very good organization, in many cases is not enough to do on-site preservation work. is not recommended to play the "silent" sound of another problem it's resuming playback takes a lot of trouble. For example, when an iOS program is woken up in the background by VoIP, it is not able to directly get AudioUnit to start broadcasting again. If Audiooutputunitstart () is called at this point, an error code is returned, even if no program at the foreground is running. At this point you cannot get the program back into a stable state. Some inexperienced programmers like to use Audiosessioninterruptionhandler to do so-called AutoPlay recovery, but they don't actually notice that Audiosessioninterruption's state recovery callback is not guaranteed to be called. AccountsPre-test can automatically restore the call, probably only the built-in Phone dialer, and some very special scenes (such as you use a MP3 player interrupt audiosession, and then kill the MP3 player process, and then reset the interrupted program back to the foreground). Often the result is that you are happy to find that the program is fine, and then in the production environment to find a variety of occasional crashes or startup failures. voipsocket voipsocket can be run in the background. When the program enters the background, the whole program is actually suspended, but the voipsocket is not due to system control. My observation is that every time a new data comes in, the program wakes up and executes for about a few seconds and then goes into hibernation again. StackOverflow said it was 10 seconds, but I'm not sure, maybe my experiment wasn't accurate enough.
Two ways to implement iOS long-time background: audiosession and VoIP (GO)