Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I was trying to run some services in the background so I struck the control in the background by using a while(1) loop in the background delegate for some time. On the emulator it is working fine but on transfering it to my iPad, the app is crashing after going into the background.

Does the while(1) loop not work for on the device?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
208 views
Welcome To Ask or Share your Answers For Others

1 Answer

On emulator it is working fine but on transfering it to the Ipad device , the app is getting crashed after going in to the background.

If I interpret correctly this that you are writing, what I think is that your app gets killed on iOS devices simply because you are not allowed, except in a few spare cases, to run a thread in your app when the app is "in background" (i.e., after the user has "quit" it by clicking on the home button).

So, if I am right in my reading what is happening, either your app is in a specific class of apps (see later), or the only thing you can do is "registering" a background thread to run for a limited amount of time after the app goes in the background.

Excerpt from Background Execution and Multitasking

Most apps are moved to the suspended state shortly after entering the background. Only apps that provide important services to the user are allowed to continue running for any amount of time.

As much as possible, you are encouraged to avoid executing in the background and let your app be suspended. If you find you need to perform background tasks, here are some guidelines for when that is appropriate:

You need to implement at least one of several specific user services.

You need to perform a single finite-length task.

You might be especially interested in the "Implementing Long-Running Background Tasks":

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

Apps that play audible content to the user while in the background, such as a music player app

Apps that keep users informed of their location at all times, such as a navigation app

Apps that support Voice over Internet Protocol (VoIP)

Newsstand apps that need to download and process new content

Apps that receive regular updates from external accessories


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...