iOS 7 - Background Location app getting killed when getting a background location

user3431473

I have checked previous stackoverflow regarding this issue and have not gotten a proper answer. I have CLLocationManager setup with region monitoring and getting location updates in the background. I have enable the capabilities of the app to be Backgroud location update.. However I see that when I get the location update I get killed when I do some processing.. i.e. get the location and send it over to a server.. Any ideas why this is happening.. I have added log messages for all app delegates and I don't see any of them being fired either.. Any pointers will be appreciated..

For #1 below are you suggesting:

- (void) _processNewLocationFromManager:manager

{
    // Process
}
- (void)locationManagerUpdatedLocation:(CSLocationManager *)manager
{
    BOOL isBackground = [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground;
    if (!isBackground || (isBackground && self.bgTask == UIBackgroundTaskInvalid)) {
        if (isBackground ) {
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                [self beginBackgroundUpdateTask];
                [self _processNewLocationFromManager:manager];
                [self endBackgroundUpdateTask];
            });
        } else {
            [self _processNewLocationFromManager:manager];
        }
    }
}

- (void) beginBackgroundUpdateTask
{
    self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [self endBackgroundUpdateTask];
    }];
}

- (void) endBackgroundUpdateTask
{
    [[UIApplication sharedApplication] endBackgroundTask: self.bgTask];
    self.bgTask = UIBackgroundTaskInvalid;
}
Gruntcakes

1) Its supposed to redundant and not needed when you use background location, however I've found if you're not getting the execution behaviour you expect when using location then throwing in a beginBackgroundTaskWithExpirationHandler when updateLocations: gets called can sometimes fix issues like this.

2) Another thing that you could try is setting pausesLocationUpdatesAutomatically to NO to see if it fixes things for you, but if it does it could use the batteries some more.

3) Also another thing to try is if you have other background modes set at the same time as location (in particular backgroundFetch and remoteNotifications) you could try toggling them off temporarily to see if its having an adverse affect.

4) One final thing, see if there are any other location based apps installed on your phone which are currently running, in my experience I've found if there's more than one location app running and they have different location manager setting set then one app can affect the behaviour of the other.

None of these should have any affect on your program and they might not. And people reading this might think these suggestions are crazy and just should not work.However I've been developing a couple of different location apps in parallel for the past few months and after many many many many debug sessions, logging sessions, observing location app behaviour when running in the background, I've come to the definite conclusion and am 100% convinced that all is not as it seems and is supposed to be (nor as is documented, nor is as it should be according to accumulated group wisdom and stack overflow answers) when it comes to location behaviour.

There's something mysterious and screwy going on in location land sometimes.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting location for an iOS app when it is in the background and even killed

From Dev

getting location updates with background service

From Dev

getting location updates with background service

From Dev

Getting too frequent location updates in the background

From Dev

Best practices: Getting location updates in background

From Dev

IOS Getting location updates when app terminated without using significantChange

From Dev

iOS 7 background location service stops

From Dev

Core Data table getting wiped out when implementing background fetch for app icon badge in iOS7

From Dev

UIAutomation : Change location when the app is in background

From Dev

Application getting Killed when kept in Background for Few minutes

From Dev

Application getting Killed when kept in Background for Few minutes

From Dev

Why nohup background process is getting killed?

From Java

Periodic iOS background location updates

From Dev

Background Location

From Dev

Background Location

From Dev

How to hide status bar message when app is using background location services in iOS

From Dev

Start Location Manager in iOS 7 from background task

From Dev

Why background location is not working after kill/Terminate app in iOS 9.3

From Dev

Phonegap every 5 minutes wake app in background to check location iOS

From Dev

Not getting the location

From Dev

Android location service stop working when app destroyed or goes in background

From Dev

Is it possible to get logs for when an app is trying to access location while in the background?

From Dev

Issues getting device/user location with iOS App, Swift

From Dev

IOs7 app crashing when in background

From Dev

iOS 7 Background Fetch When the App is Not Running

From Dev

Getting location when button is clicked

From Dev

Getting location updates when app is inactive stops after 2 updates

From Dev

Meteor + Cordova: getting user's location when app is terminated

From Dev

It is possible to watch the location in the background on Mobile (iOS / Android)?

Related Related

  1. 1

    Getting location for an iOS app when it is in the background and even killed

  2. 2

    getting location updates with background service

  3. 3

    getting location updates with background service

  4. 4

    Getting too frequent location updates in the background

  5. 5

    Best practices: Getting location updates in background

  6. 6

    IOS Getting location updates when app terminated without using significantChange

  7. 7

    iOS 7 background location service stops

  8. 8

    Core Data table getting wiped out when implementing background fetch for app icon badge in iOS7

  9. 9

    UIAutomation : Change location when the app is in background

  10. 10

    Application getting Killed when kept in Background for Few minutes

  11. 11

    Application getting Killed when kept in Background for Few minutes

  12. 12

    Why nohup background process is getting killed?

  13. 13

    Periodic iOS background location updates

  14. 14

    Background Location

  15. 15

    Background Location

  16. 16

    How to hide status bar message when app is using background location services in iOS

  17. 17

    Start Location Manager in iOS 7 from background task

  18. 18

    Why background location is not working after kill/Terminate app in iOS 9.3

  19. 19

    Phonegap every 5 minutes wake app in background to check location iOS

  20. 20

    Not getting the location

  21. 21

    Android location service stop working when app destroyed or goes in background

  22. 22

    Is it possible to get logs for when an app is trying to access location while in the background?

  23. 23

    Issues getting device/user location with iOS App, Swift

  24. 24

    IOs7 app crashing when in background

  25. 25

    iOS 7 Background Fetch When the App is Not Running

  26. 26

    Getting location when button is clicked

  27. 27

    Getting location updates when app is inactive stops after 2 updates

  28. 28

    Meteor + Cordova: getting user's location when app is terminated

  29. 29

    It is possible to watch the location in the background on Mobile (iOS / Android)?

HotTag

Archive