开发者

allow background mode, but terminate conditionally?

I'm setting "Application does not run in background" to NO

which means, it can go background and resumed later.

I'm putting some code in "applicationDidEnterBackground", and I would like to force quit the app when desirable. (when there's nothing to do in background.)

I read 'exit' is not recommended.

Can I post a message which will result in something like applicationWillTerminate maybe?

  • Edit

Let me clarify why I would want that, I want my app to run background when it's downloading something.. via beginBackgroundTaskWithExpirationHandler

But if user isn't downloading anything, I can safely 开发者_Python百科quit the application.

Thank you


The general Apple approach on iOS is that applications should never terminate themselves, for any reason.

It's important to understand that when your application is 'running' in the background, it's not really running: the 'Application does not run in background' key is basically there to ensure backwards compatibility with applications built for iOS 3 and lower, which tend to make certain assumptions about how the user will enter the app. There are very few reasons why a new app wouldn't support it.

Basically, don't bother: I suppose you could technically call exit(), but Apple will hate you for it, and it's bad style for the platform.


You don't need to worry about this.

If you have work to do in the background and you set up a background task then it'll run for as long as it needs and execute its handler when done.

What you don't seem to be aware of is that if you have nothing to do in the background, your app is simply suspended and in fact does not run.

As this is the case, there's nothing you need to do, quitting the app won't gain you anything that you don't already get with suspension.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜