views:

105

answers:

1

Hello,

I want to detect application states and send it to the server. In the new OS4, with multitasking there are some methods available to help detecting the states:

  • application:didFinishLaunchingWithOptions:
  • applicationDidBecomeActive:
  • applicationWillResignActive:
  • applicationDidEnterBackground:
  • applicationWillEnterForeground:
  • applicationWillTerminate:

I read that now, we have to use applicationDidEnterBackground instead of applicationWillTerminate. My problem is that i need them both.

When the user send the app to the background, it has the state sleep. But when the user close the app ( from the multitask bar ) the state is closed. So i need to detect both, when the user send the app to the background and when the user ( or the system ) close it.

Is there anyway or workaround to make this?

I try subscribing to UIApplicationWillTerminateNotification but it doesn´t work.

Thanks in advice.

A: 

The application will quit notification is no longer fired on iOS 4 (as I am led to believe).

When the user hits the home button, the app is sent to the background, and you will get the did enter background notification. But when a user closes the app from the multitask bar, or if the system closes it, the app is sent a SIGKIL message and quits immediately, firing no notifications or delegate methods.

Jasarien
Ok, thanks. So u cannot track "sleep" state and "closed" state.
You might be able to take advantage of the 'didEnterBackground:` notification. The only problem I see is that you'd need to make use of the background task API in order to send the data to your server - and if that's the only reason you're using it, Apple aren't going to allow it. It's similar to using location services only for advertising, it's not allowed. So unless you're also sending other stuff that is useful for the user, it's not going to be allowed by Apple.
Jasarien
I dont need to use the background task API. I just need to know when the users has the application active in background or closed, and notify the server when the states changes. For example, i want to show comments of users with the app active or in background, but i dont want to show comments of users with the app closed.I dont believe yet that u cannot track active, inactive and closed states of an application...
You WILL need the background task API - When your app is suspended and put into the background how else are you going to notify your server? Your app stops running when it goes into the background unless you instruct the system to allow you run some code in the background.
Jasarien
Yep, u are right, thanks. I´ll try to post my solution to the problem when i achieve it. Thanks again.