Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

While(1) loop is not working in background in IOS

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...