Application killed by OS in ios7 after few seconds -edit

I am building a navigation-based application for iOS 7 because I am taking user location data using the CoreLocation infrastructure,

The requirement for the application is to start receiving the location of users in the background at a certain time, for this I applied Silent Pushnotification using the method didReceiveRemoteNotification fetchCompletionHandler:,

I successfully implement using Silent Pushnotification and call startUpdatingLocation, and I can get location data in the delegate method:

Using this payload:

{"aps" : {"content-available" : 1},"SilentPush" : "4"}

I turned on locationand remote notificationfor the background mode:

enter image description here

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
     __block UIBackgroundTaskIdentifier bgTask =0;
    UIApplication  *app = [UIApplication sharedApplication];
     bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [self.locationManager startUpdatingLocation];

 }];

didUpdateLocations

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
        lastLoc=[locations lastObject];
        [logFile addLocObject:[NSString stringWithFormat:@"Loc: %@",lastLoc]];
}

But the problem is this:

location , - , , , "didFinishLaunhing", , os , ,   Diagnostics & usage :

Application Specific Information:
MockUpApp2[390] has active assertions beyond permitted time: 
{(
    <BKProcessAssertion: 0x145ac790> identifier: Called by MockUpApp2, from -[AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] process: MockUpApp2[390] permittedBackgroundDuration: 40.000000 reason: finishTaskAfterBackgroundContentFetching owner pid:390 preventSuspend  preventIdleSleep  preventSuspendOnSleep 
)}

, push-,

, , .

.

.. , , XCode , . .

1

@Stephen Darlington , ,

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
        [self.locationManager startUpdatingLocation];

}

didUpdateLocations ,: (

?

Edit 2

Apple Doc :

If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method.

SO, , ,?

+3
3

, iOS , . Mac Windows, ( iOS 7).

, : , . "".

  • - . , . , ( , ). Apple , , , 40 . , , beginBackgroundTaskWithExpirationHandler. , endBackgroundTask:
  • -, beginBackgroundTaskWithExpirationHandler:. ,

: beginBackgroundTaskWithExpirationHandler:. startUpdatingLocation:.

+4

CLLocation , , .

, beginBackgroundTaskWithExpirationHandler. , . , backgroundTask CLLocationDelegate.

, , Apple . . , . , . , , . , .

, , , .

, , , . , , .

- :

  • . /. .
  • . , .
  • , . , . 24 , .

, . , , , CL -. , . , .

, , GitHub.

TTLocationHandler

, , , , , .

, , , . .

, .

. startUpdatingLocation. , .

.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    __block UIBackgroundTaskIdentifier bgTask =0;
    UIApplication  *app = [UIApplication sharedApplication];
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
          // Do something here. Perhaps you'll log the error or respond with some fall back
          // This block will only be run if the handler expires without having been ended
          // In that case, you need to end it now or you will crash
          If (bgTask != UIBackgroundTaskInvalid) {
              [app endBackgroundTask:bgTask];
              [bgTask = UIBackgroundTaskInvalid];
          }

      }];

      // This is where the code you intend to run in the background starts

     [self.locationManager startUpdatingLocation];

     // Now tell the system you are finished, ending background task normally before exit

     If (bgTask != UIBackgroundTaskInvalid) {
         [app endBackgroundTask:bgTask];
         [bgTask = UIBackgroundTaskInvalid;
     }
}
+3

beginBackgroundTaskWithExpirationHandler: , , .
, , .
, .
, - , .
[]
, , , .

+1

All Articles