Developing iPhone iOS4 Application Behavior: Running in the Background and Completing the Application

We are developing an iPhone GPS application for car drivers.

As you probably know, iOS4 introduced multitasking, so our application can run in the background - and this is so. This is part of its functionality.

The problem is the standard method for closing applications on iOS4. Here are two scenarios:

1) The user wants to put the application in the background:

Typically, on an iOS4 iPhone, it's as simple as tapping the home button.

2) The user wants to disable the application (i.e. after arriving at the destination):

The standard procedure for iPhone iOS4 is as follows:

  • press the "home" button - the application goes into the background
  • press the home button twice - a list of running applications will appear
  • press and hold one of the application icons - all the “shake” and “-” icons will appear on each of them.
  • tap '-' sign on the application icon the user wants to complete

The user must interrupt our application every time he arrives somewhere (for example, twice a day) in order to save his battery. If he does not, the GPS will consume all the battery power very quickly. In addition, we cannot turn off GPS while running in the background, because we need accurate location information for the basic functionality of the application.

Of course, you cannot change the behavior of the home button from your application (to be accepted in the AppStore). Also, I don’t think it would be a good decision to change the expected behavior to something completely different than other applications on the iPhone platform.

What do you think about this? Do you know any good solution. We have one idea, but I don’t want to offer anything yet.

Our idea for the solution is very simple: Just show the small "x" button in the upper right corner of the screen. Clicking on it terminates the application (possibly after some confirmation question).

This solution has one big advantage: it does not change the default behavior of the system - users familiar with using iOS4 multitasking can still press the home button to launch the application in the background and close it in the iPhone-style.

What do you think?

+7
iphone ios4 multitasking application-design
source share
9 answers

Apple recommends doing this (iPhone App Programming Guide):

Applications can only be registered for significant changes in location. (Recommended) The significant location change service is available on iPhone OS 4 and later for cellular radio devices. It offers a low-power way to get location data and is highly recommended. New location updates are only available when the position of users changes significantly. If an application is paused during the launch of this service, new location updates will cause the application to wake up in the background to process them. Similarly, if an application terminates during the execution of this service, the system automatically starts the application when new location data becomes available.

Have you tried using it by calling the startMonitoringSignificantLocationChanges method for CLLocationManager?

Exiting the application should be performed only as a last resort. You can turn off location services when you’re not using them without exiting the application. You can call stopUpdatingLocation in the CLLocationManager to disable it.

- (void) stopUpdatingLocation

You should call this method when your code should no longer receive location-related events. Disabling event delivery enables the receiver to disable the associated equipment (and therefore save energy) when customers do not need location data. You can always restart the generation of location updates by calling the startUpdatingLocation method again.

+6
source share

Perhaps there is a potential workaround? It really depends on your application. Here is what I did for the application that I developed to run GPS in the background.

I highly recommend you take a look at the iOS4 startMonitoringSignificantLocationChanges API in the CLLocationManager.

While driving you will receive an update accurate to within 500 meters every 2 km or so. If this is not enough for your application, you can turn on the GPS equipment ONLY when your application is running by the system. Thus, you can still get very accurate readings every ~ 2 km, but save battery.

You can use smart tracking and display methods to "fake" missing data.

I conducted an experiment against the backdrop of GPS events with 8 iPhone 3GS-es. Results published here: iPhone background GPS / signficantLocationChange preliminary event analysis

+3
source share

Why don't you create a button that they can click when they arrive at their destination, which sets the flag “Arrived” = “YES”.

Then add this to the application so that it is called when they press the home button.

 - (void)applicationWillResignActive:(UIApplication *)application { if (Arrived) { exit(0); } } 

This will completely disable the application when they press the home button, but only if they indicate that they have arrived. Otherwise, it will be in the background.

+2
source share

Since you need to run in the background for location purposes, and Apple will not allow you to terminate your own application, you are stuck with the fact that the user must understand that they need to terminate the application on their own in order to save energy.

The quick fix is ​​to turn off location services after you reach your goal. You can even warn the user about this, and as soon as they click the "OK" button, you will stop him from starting and / or starting in the background if the application is paused.

+1
source share

If the user moves and moves, they need accurate information, really. This does not mean that you cannot use startMonitoringSignificantLocationChanges , right?

In other words, use a timeout to stop monitoring (and power to the GPS equipment) exactly when you stopped receiving “significant changes” in the time that you can configure. Start tracking again when you receive them again.

+1
source share

If the user is actively navigating a route and they are going to background, continue to use GPS if they are at their destination, use the above suggestions and switch to startMonitoringSignificantLocationChanges or disable location services. The gray area is if the user is close to the destination and is executed using GPS, but did not bother to stop navigation. that is, their purpose is not correct when the GPS thinks that it, etc. Now you are actively swimming, but you will never reach your goal. In order not to disturb the user or rely on some parameters, I suggest monitoring non-movement or at least idle, and then use this as a key to ensure that the user no longer relies on you, and switch to low-power navigation.

0
source share

I don’t have Xcode in front of me (PC at work), so I can’t find any methods that you could use, but I believe that the TomTom application does some kind of monitoring when working in the background, because I remember warning that he will sleep. I remember that this happened after 5-10 minutes.

0
source share

Can I turn off GPS monitoring from the application? Could you add a button to simply disable it, and not exit the entire application? i.e. Put the app to sleep, as mentioned about the TomTom app.

If so, you may want to somehow change the user interface so that the user can see that the GPS activity is not working, so the application does not have full functionality.

0
source share

I have a solution that I use in a similar application. I have a Background button in my navigation bar. The user clicks on them, and they are notified that when they click "Home", they will work in the background. Each time the application is launched or re-activated, pressing the Home button again will cause the application to not start.

Then, when the "Home" button is clicked, I check the flag to see if we need to go into the background. I avoid the background by simply disabling GPS (which, when the location is set to UIbackgroundModes, causes the application to pause)

Make sense?

0
source share

All Articles